【发布时间】:2016-06-29 21:34:07
【问题描述】:
我有这种元素:
{ "_id" : 1,
"docs" : [
{ "key": "blah", "count": 2},
{ "key": "wow", "count": 10}
]
},
{ "_id" : 2,
"docs" : [
{ "key": "blah", "count": 11}
}
我想检索未定义 docs.key == "wow" 的元素。在这种情况下,元素"_id": 2。
这个查询我得到相反的结果:
db.getCollection('myCollection').find(
{
"docs.key": "wow"
}
);
我尝试了$exists 和aggregate 的组合,但没有找到合适的解决方案。
【问题讨论】:
-
相关但不相同:stackoverflow.com/q/5719408/316700, stackoverflow.com/q/16221599/316700 因为在我的示例中,我正在寻找一个复杂元素到一个数组中。
标签: mongodb