Reputation: 1146
I am trying to generate a mongo query that will return all entries where mktid=x and selctionid=y as per below. SelectionId is a member of an actors array as per below.
I have tried multiple things like this
db.getCollection('mycollection').find({mktid:"334455555",'actors.selectionId' : "443311555"})
and
db.getCollection('mycollection').find({mktid:"334455555",'actors.0.selectionId' : "443311555"})
The DB:
{
"_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", ---- ---
Upvotes: 0
Views: 79
Reputation: 3138
db.getCollection('mycollection').find({mktid:"334455555", actors: {
$elemMatch: {
selectionId: "443311555"
}
}
});
See the "Query an Array of Documents" section here: http://docs.mongodb.org/manual/reference/method/db.collection.find/
Upvotes: 2