I have a collection Project with documents that look like the following :
{
_id: ObjectId(...),
name: "some name",
members: [
{
user: ObjectId(...),
joined: false,
...
},
{
user: ObjectId(...),
joined: true,
...
},
{
user: ObjectId(...),
joined: true,
...
},
...
]
Given two user ids, I would like to query all the documents where members contains at least both users with joined equal to true. Additional members could be present, but the two must be present.
I have no clue what to do, especially with $elemMatch. Any idea ?
Intuitively, I would have done something like this :
Project.find({
members: {
$elemMatch: [
{
user: firstId,
joined: true
},
{
user: secondId,
joined: true
}
]
}
})