我有一个名为test的集合,如下所示 {“ _id”:ObjectId(“ ciwhciwiwh686ddd”) “ playerName”:“乔恩·多伊” “玩家团队”:“ Team1” “点”:[ {“ date”:“ 01-01-2018”,“ score”:145}, {“ date”:“ 01-01-2019”,“ score”:200} ]
}
浏览了mongoDB的官方文件并尝试了以下方法
db.test.find({"Player Team": "Team1"}, {"points": {"date":"01-01-2018"}})
我也尝试过
db.test.find({"Player Team": "Team1"}, {"points.date":"01-01-2018"})
我得到了不受支持的投影选项:
答案 0 :(得分:0)
$ elemMatch运算符匹配包含一个包含至少一个与所有指定查询条件匹配的元素的数组字段的文档。
db.test.find({“ Player Team”:“ Team1”},{“ points”:{$ elemMatch {“ date”:“ 01-01-2018”}}}}