mongodb query by sub-field

可紊 提交于 2019-12-04 22:27:29

Try:

db.XXX.find({ "_id.module" :  "B" });

The difference is your original query would be trying to match on that entire subdocument (i.e. where _id is a subdocument containing a "module" field with value "B" and nothing else)

Reference: MongoDB Dot Notation

NPKR

For Exact match on Subdocument

    db.bios.find(
   {
     '_id.module': 'B'
   }
)

the query uses dot notation to access fields in a subdocument:

Refference link

Use dot notation:

db.XXX.find({ "_id.module" : "B" })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!