|
When a regex is inside an $in, the regex is actually evaluated against strings, acting like a regex match predicate rather than an equality predicate:
MongoDB Enterprise > db.c.find({a: {$in: [1, /foo/]}})
|
{ "_id" : ObjectId("5b6b69f6c3d88f417d6971c0"), "a" : /foo/ }
|
{ "_id" : ObjectId("5b6b69fcc3d88f417d6971c1"), "a" : 1 }
|
{ "_id" : ObjectId("5b6b6a04c3d88f417d6971c2"), "a" : "foobar" }
|
This means that $in is not simply syntactic sugar for an $or of equalities. Another unfortunate consequence is that the $lookup join predicate cannot always be expressed as an $in; if there is a regex it must be expressed as an $or.
|