I'm using the JavaScript mongodb driver from nodejs. I want to do this query in my JavaScript function:
db.mycollection.find({Zip:/^94404/});
The mongo client retrieves 8 docs that match this criteria. However my JavaScript code does not fetch any documents.
DataProvider.prototype.findByZipcode = function(zipCode, callback) {
this.getCollection(function(error, collection) {
if (error)
callback(error);
else {
var qs = '{Zip:/^'+zipCode+'/}';
collection.find(qs).toArray(function(error, results) {
if (error)
callback(error);
else
callback(null, results);
});
}
});
};
I also tried
<pre>
var qs = {Zip: '/^'+zipCode+'/'};
</pre>
Btw, I find exact match works fine, but that's not what I want.
ie.
<pre>
var q = {'Zip' :zipCode};
</pre>