且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从子数组中找到文档?

更新时间:2023-02-26 19:06:43

您需要使用 dot符号 指定嵌入文档的完全匹配并使用$in 操作符来选择那些获得或被提名***影片的文件

You need to use the dot notation to specify an exact match on the embedded document and use the $in operator to select those documents that won or were nominated for best picture

您不应该使用 $or 操作符在这里,因为如果索引不支持所有子句,它将执行集合扫描,如 文档.

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