mongodb - mongoose node.js, query with $lt and $gt not working -
i want pupils last mark between 15 , 20. so, perform following query in mongodb using mongoose: models working fine (all other queries ok).
pupils.find({"marks[-1].value": {'$lt' : 20 }, "marks[-1].value" : { '$gt' : 15 }}, function(err, things){ this not working, there missed ?
* update *
i found like:
pupils.find({ "marks[-1].value": {$gt : 15, $lt : 20}}); but not work either. there way last mark of marks array in case ?
lets consider pupils collection:
pupils { _id, marks(integer), latestmark(int) } i suggest add latest mark pupil document(as can see @ document above), , update each time when adding new mark nested collection. able query on this:
db.pupils.find({ "latestmark": {$gt : 15, $lt : 20}}); also can query latest mark using $where, care because:
javascript executes more native operators, flexible
Comments
Post a Comment