find the document from sub array?

后端 未结 2 1124
悲&欢浪女
悲&欢浪女 2020-12-21 06:15

I have a collection with documents that look like this:

\"awards\" : {
    \"oscars\" : [
        {\"award\": \"bestAnimatedFeature\", \"result\": \"won\"},
         


        
2条回答
  •  既然无缘
    2020-12-21 06:38

    According to the MongoDB Query documentation, you can match a field in an embedded document within an array by concatenating its name to the name of the array like so:

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

提交回复
热议问题