假设我有以下文件
Article { Comment: embedMany }
Comment { Reply: embedMany }
Reply { email: string, ip: string }
我想做一个查询, Select distinct Reply.ip
,其中Reply.email = xxx
像这样的东西,只是不起作用..
db.Article.find("Comment.Reply.email" : "xxx").distinct("Comment.Reply.ip")
JSON export:
{
"_id":{
"$oid":"4e71be36c6eed629c61cea2c"
},
"name":"test",
"Comment":[
{
"name":"comment test",
"Reply":[
{
"ip":"192.168.2.1",
"email":"yyy"
},
{
"ip":"127.0.0.1",
"email":"zzz"
}
]
},
{
"name":"comment 2 test",
"Reply":[
{
"ip":"128.168.1.1",
"email":"xxx"
},
{
"ip":"192.168.1.1",
"email":"xxx"
}
]
}
]
}
I run : db.Article.distinct("Comment.Reply.ip",{"Comment.Reply.email" : "xxx"})
I expect : ["128.168.1.1", "192.168.1.1"]
I get : ["127.0.0.1", "128.168.1.1", "192.168.1.1", "192.168.2.1"]