【发布时间】:2011-09-14 16:49:08
【问题描述】:
假设我有以下文件
Article { Comment: embedMany }
Comment { Reply: embedMany }
Reply { email: string, ip: string }
我想做一个查询,选择不同的Reply.ip where Reply.email = xxx
类似的东西,只是它不起作用..
db.Article.find("Comment.Reply.email" : "xxx").distinct("Comment.Reply.ip")
JSON 导出:
{
"_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"
}
]
}
]
}
我跑:db.Article.distinct("Comment.Reply.ip",{"Comment.Reply.email" : "xxx"})
我期待:["128.168.1.1", "192.168.1.1"]
我明白了:["127.0.0.1", "128.168.1.1", "192.168.1.1", "192.168.2.1"]
【问题讨论】:
-
请为“我跑步”、“我期望”、“我得到”投上一票,只要所有问题的格式都像这样!
-
这是解决方案的变体stackoverflow.com/a/13864518/358013
标签: mongodb