【发布时间】:2017-07-01 17:23:49
【问题描述】:
我的文档结构如下:
{
"field1": "value",
"field2": "value",
"items": [
{
"inField1": "value1",
"inField2": "value2",
"votes": {
"count": 2,
"people": [
{
"username": "user1",
"image": "http://image/to/user1/profile.jpg"
},
{
"username": "user2",
"image": "http://image/to/user2/profile.jpg"
}
]
}
},
{
"inField1": "value3",
"inField2": "value4",
"votes": {
"count": 1,
"people": [
{
"username": "user1",
"image": "http://image/to/user1/profile.jpg"
}
]
}
}
]
}
现在我需要所有 item(项目字段的单个对象),其中 votes 属性的任何 people 属性的用户名都为 user1?
在上述示例中,它应该返回两个 items,因为它们都包含 user1 在用户名属性中,但如果我搜索user2 那么只有第一个项目应该被返回。
【问题讨论】:
标签: mongodb mongodb-query nosql