title: pymongo where clause with a complex function
body: <p>How do I write the below search query using pymongo? This query works well for me in the db.</p>
  
  <pre><code>{$where: function() {
  var deepIterate = function  (obj, value) {
      for (var field in obj) {
          if (obj[field] == value){
              return true;
          }
          var found = false;
          if ( typeof obj[field] === 'object') {
              found = deepIterate(obj[field], value)
              if (found) { return true; }
          }
      }
      return false;
  };
  return deepIterate(this, "573c79aef4ef4b9a9523028f")
  </code></pre>
  
  <p>}}</p>