db.products
{"product":"iphone",
"people_have_this":[001, 002, 003, 004]} //objectID
{"product":"samsung",
"people_have_this":[001, 004]}
{"product":"nokia",
"people_have_this":[001, 002, 003]}
db.users
{"name":"john",
"id":"001"}
{"name":"peter",
"id":"002"}
如何获得John的产品清单?我的期望是什么
[{"product":"iphone",
"people_have_this":[001, 002, 003, 004]},
{"product":"samsung",
"people_have_this":[001, 004]},
{"product":"nokia",
"people_have_this":[001, 002, 003]}]
答案 0 :(得分:0)
如果您知道John的id,那么这是一个简单的查询......
db.products.find( { people_have_this: "001" } );