我有这个系列 { "name" : "montalto", "users" : [ { "username" : "ciccio", "email" : "aaaaaaaa", "password" : "aaaaaaaa", "money" : 0 } ], "numers" : "8", "_id" : ObjectId("5040d3fded299bf03a000002")} 如果我想搜索名为montalto的集
{ "name" : "montalto", "users" : [ { "username" : "ciccio", "email" : "aaaaaaaa", "password" : "aaaaaaaa", "money" : 0 } ], "numers" : "8", "_id" : ObjectId("5040d3fded299bf03a000002") }
如果我想搜索名为montalto的集合和名为ciccio的用户,我正在使用以下查询:
db.coll.find({name:'montalto', users:{username:'ciccio'}}).count()
但它不起作用.哪里出错了?
您必须使用 dot notation来匹配嵌入式数组对象的内部:db.coll.find({name: 'montalto', 'users.username': 'ciccio'}).count()