There's two ways to interpret your condition
all "foos" on the field "bar" that satisfies following condition: "uid" = 2 and "mid" in [14, 18]
Do you mean "find all documents in the foo collection such that there is an element e of the bar array satisfying e.uid = 2 and e.mid is an element of [14, 18]"? If so, the MongoDB query, written in the mongo shell, is
db.foo.find({ "bar" : { "$elemMatch" : { "uid" : 2, "mid" : { "$in" : [14, 18] } } } })
Do you mean "find all documents in the foo collection such that there is a bar.uid value of 2 and bar.mid value in [14, 18]"? If so, the MongoDB query, written in the mongo shell, is
db.foo.find({ "bar.uid" : 2, "bar.mid" : { "$in" : [14, 18] } })
The following example demonstrates the differences between these queries:
> db.foo.drop()
> db.foo.insert({ "_id" : 0, "bar" : [{ "uid" : 2, "mid" : 14 }] })
> db.foo.insert({ "_id" : 1, "bar" : [{ "uid" : 2, "mid" : 99 }, { "uid" : 3, "mid" : 18 }] })
// first version
> db.foo.find({ "bar" : { "$elemMatch" : { "uid" : 2, "mid" : { "$in" : [14, 18] } } } })
{ "_id" : 0, "bar" : [{ "uid" : 2, "mid" : 14 }] }
// second version
> db.foo.find({ "bar.uid" : 2, "bar.mid" : { "$in" : [14, 18] } })
{ "_id" : 0, "bar" : [{ "uid" : 2, "mid" : 14 }] }
{ "_id" : 1, "bar" : [{ "uid" : 2, "mid" : 99 }, { "uid" : 3, "mid" : 18 }] }