I'm trying to query a collection and filter based on values nested within an array and a second array using elemMatch.
{
"email": "[email protected]",
"project" [ {
projectId: ObjectId("123"),
preference: [
{"name": "name1", "value": true},
{"name": "name2", "value": false}
]
},
{
projectId: ObjectId("456"),
preference: [
{"name": "name1", "value": true},
{"name": "name2", "value": true}
]
}
]
},
{
"email": "[email protected]",
"project" [ {
projectId: ObjectId("123"),
preference: [
{"name": "name1", "value": false},
{"name": "name2", "value": true}
]
},
{
projectId: ObjectId("456"),
preference: [
{"name": "name1", "value": true},
{"name": "name2", "value": true}
]
}
]
}
I've tried a few different variations of merging the below two queries into one to try and achieve my goal of returning.
{email: "[email protected]"}
db.user.find({"project":{"$elemMatch":{"projectId":ObjectId("123")}}}, {email: 1})
db.user.find({"project.preference":{"$elemMatch":{"$and":[{"name":"name1"}, {"value": true}]}}}, {email: 1})