Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的架构如下所示:
{ _id: "myid" user: [{"name":"Bob"}, {"name":"Jenny"}] }, { _id: "myid2" user: [{"name":"John"}, {"name":"Jenny"}] }, { _id: "myid3" user: [{"name":"John"}, {"name":"Bob"}] }
我想查找 Bob 是用户的所有文档。他可以是阵列中的任何位置。这可以做到吗?
谢谢。
1) db.test.find({'user.name': 'Bob'})
2) db.test.find({'user' : { $elemMatch : {'name' : 'Bob'}}})