node.js - Passing variables into a query in mongoose in the first argument -


i using mean stack, have entry in mongodb

{ "_id" : objectid("5577467683f4716018db19ed"), "requestmatrix" : { "1698005072" : { "rideid" : "641719948", "status" :"accepted" },"1698005073" : { "rideid" : "641719545", "status" :"rejected" }  },  "partners":[ { "customernumber" : 1698005072 }, { "customernumber" : 1698072688 } ]} 

i want query db return me entire document based on whether status accepted or rejected.

when run below query in command prompt, expected answer

db.joinedrides.find({'requestmatrix.1698005072.status':"accepted"}) 

but when want same nodejs, stuck number 1698005072 in above query variable, not able write query that.

tried this

var criteria = "'requestmatrix.'"+customernumber+"'.status'";     joinedride.find({criteria:"accepted"},function(err,joinedrides){      }) 

where customernumber vary different requests, in above mentioned case value 1698005072

any appreciated.

you need this:

var query = {}; var criteria = "requestmatrix." + customernumber + ".status"; query[criteria] = "accepted"  joinedride.find(query,function(err,joinedrides){  }) 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -