Gebruik $and
:
db.getCollection('collection_name').find({
$and: [{
TitleData: {
$elemMatch: {
UserId: ObjectId("57a87f5cc48933119cb96f9b"),
UserId: ObjectId("57a87f5cc48933119cb96fa7")
}
}
}, {
TitleData: {
$elemMatch: {
$ne: {
"Res": 2
}
}
}
}]
}));
Test de uitvoer van de console met uw verzamelingsobjecten:
> db.collection.find({ $and: [{ TitleData: { $elemMatch: { UserId: ObjectId("57a87f5cc48933119cb96f9b"), UserId: ObjectId("57a87f5cc48933119cb96fa7") } } },{ TitleData: { $elemMatch: { $ne: { "Res": 2 } } }}]});
{ "_id" : ObjectId("57a8a6c3c48933256cfd8368"), "Title" : "T1", "TitleData" : [ { "UserId" : ObjectId("57a87f5cc48933119cb96f9b"), "Res" : 2 }, { "UserId" : ObjectId("57a87f5cc48933119cb96fa7"), "Res" : 2 }, { "UserId" : ObjectId("57a87f5cc48933119cb96f96"), "Res" : 2 }, { "UserId" : ObjectId("57a87f5cc48933119cb96f9c"), "Res" : 2 }, { "UserId" : ObjectId("57a87f5cc48933119cb96f9d"), "Res" : 0 } ] }
BEWERKEN Niet alle console-uitvoer toegevoegd...