Consider such a collection:
> db.test.find({})
{ "_id" : ObjectId("5f969419d40c1580f2d4aa31"), "users" : { "foo@bar.com" : "baz" } }
{ "_id" : ObjectId("5f9694d4d40c1580f2d4aa33"), "users" : { "baz@test.com" : "foo" } }
I want to find documents where users
contains field foo@bar.com
.
Firstly I tried
> db.test.find({"users.foo@bar.com": { $exists: true } })
But it returned nothing. Because of the dot (.) in field's name it was looking for a such a field: users > foo@bar > com
which does not exist.
I learned that the dot in key's name can be escaped with \u002e
so I tried
> db.test.find({"users.foo@bar\u002ecom": { $exists: true } })
But it also returns nothing. I guess that I am not escaping properly. How should I do this?