mongodb - how to find a property is exist or not in an array in a collection? -


this question has answer here:

what query document use in find() command return movies in video.moviedetails collection either won or nominated best picture? may assume award appear in "oscars" array if movie won or nominated.

"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."     } 

do mean query?

db.movie.find({"awards.oscars.award":"bestpicture"}) 

input:

{     "_id" : objectid("569a7f590586bcb40f7d2532"),     "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."     } }  {     "_id" : objectid("569a7fc60586bcb40f7d2533"),     "awards" : {         "oscars" : [              {                 "award" : "bestscreenplay",                 "result" : "nominated"             }         ],         "wins" : 12,         "nominations" : 15,         "text" : "won 1 oscars. 12 wins , 15 nominations."     } } 

result

{     "_id" : objectid("569a7f590586bcb40f7d2532"),     "awards" : {         "oscars" : [              {                 "award" : "bestanimatedfeature",                 "result" : "won"             },              {                 "award" : "bestmusic",                 "result" : "won"             },              {                 "award" : "bestpicture",                 "result" : "nominated"             },              {                 "award" : "bestsoundediting",                 "result" : "nominated"             },              {                 "award" : "bestscreenplay",                 "result" : "nominated"             }         ],         "wins" : 56.0000000000000000,         "nominations" : 86.0000000000000000,         "text" : "won 2 oscars. 56 wins , 86 nominations."     } } 

Comments