mongodb query - Using Dynamic strings for querying nested mongo doc -
i'm using dot notation querying nested mongo doc. want query dynamically generated.
for eg nesting
{ "car": { "make": { "model": "some val" year : "some year" } } }
if perform query db.carcoll.find({'car.make.model':'some val'}) results. query string 'car.make.model' change car.make.year , query dynamic.
i set in variable , try query='car.make' + choice; choice variable either ".model" or ".year"
and run db.carcoll.find({query:"1989"})
i don't results in case. how handle this
not tested it, thoughts. did tried code:
var prop = "car.make." + "model" //or ""year" var query = {}; query[prop] = "1989"; db.carcoll.find(query)
Comments
Post a Comment