When I query my database with a function passed in the \"$where\" clause in nodejs, it always return me all documents in the db.
For example, if I do
This one is works for me , Just try to store a query as a string in one variable then concat your variable in query string,
var local_var = 42 var query = "{$where: function() { return this.a == "+local_var+"}}" db.test.find(query)
var local_var = 42
var query = "{$where: function() { return this.a == "+local_var+"}}"
db.test.find(query)