mongodb - find the document from sub array? -


i have collection documents this:

"awards" : {     "oscars" : [         {"award": "bestanimatedfeature", "result": "won"},         {"award": "bestmusic", "result": "won"},         {"award": "bestpicture", "result": "nominated"},         {"award": "bestsoundediting", "result": "nominated"},         {"award": "bestscreenplay", "result": "nominated"}     ],     "wins" : 56,     "nominations" : 86,     "text" : "won 2 oscars. 56 wins , 86 nominations." } 

what query document use in find() command return movies in my_collection collection either won or nominated best picture?

you need use dot notation specify exact match on embedded document , use $in operator select documents won or nominated best picture

you shouldn't use $or operator here because perform collection scan if not clauses supported indexes mention in documentation.

db.my_collection.find({      'awards.oscars.award': 'bestpicture',      'awards.oscars.result': { '$in': [ 'won', 'nominated' ] }  } ) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -