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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -