我正在尝试生成一个mongo查询,该查询将返回mktid = x和selctionid = y的所有条目,如下所示。 SelectionId是一个actors数组的成员,如下所示。
我尝试了很多这样的事情
db.getCollection('mycollection').find({mktid:"334455555",'actors.selectionId' : "443311555"})
和
db.getCollection('mycollection').find({mktid:"334455555",'actors.0.selectionId' : "443311555"})
数据库:
{
"_id": {
"$oid": "55098030e4b02da345b0a2ed"
},
"mktid": "55555555",
"dubious": false,
"state": "OPEN"
"actors": [
{
"selectionId": 3333333,
"activityid": 0,
"status": "ACTIVE",
},
{
"selectionId": 4444445gg,
"activityid": 0,
"status": "ACTIVE",
},
{
"selectionId": xccfffff,
"activityid": 0,
"status": "ACTIVE",
}
]
}
{ " _id":{ " $ oid":" 55098030e44b02da345b0a2ed" }, " mktid":" 5555552", ---- ---
答案 0 :(得分:2)
db.getCollection('mycollection').find({mktid:"334455555", actors: {
$elemMatch: {
selectionId: "443311555"
}
}
});
参见"查询文档数组"部分:http://docs.mongodb.org/manual/reference/method/db.collection.find/