在执行db.markers.find()时我的数据库中有这个结果:
{ "_id" : ObjectId("518134733198c6952f000000"), "location" : { "type" : "Point", "coordinates" : [ -48.8397216796875, -19.68656825792867 ] }, "m_info" : { "category" : "14", "sub_category" : "156", "description" : "Teste" }, "user_info" : { "email" : "user@gmail.com", "name" : "John Doe" } }
{ "_id" : ObjectId("518192d13198c69e3c000000"), "location" : { "type" : "Point", "coordinates" : [ -44.52420382953613, -17.586578222234177 ] }, "marker_info" : { "category" : "9", "sub_category" : "118", "description" : "I'm working with TI." }, "user_info" : { "email" : "user2@gmail.com", "name" : "John Doe2" } }
但是当我尝试类似db.markers.find({user_info:{email:'user@gmail.com'}})时,它没有返回任何结果 为什么这不起作用?
谢谢,
答案 0 :(得分:3)
这是因为您正在查找user_info对象正好 { email : 'user@gmail.com' }
如果您想在user_info中匹配碰巧有电子邮件为'user@gmail.com'的文档而不管子文档的其余部分使用the dot notation:
db.markers.find({ "user_info.email" : "user@gmail.com })