匹配非空文档我有一个集合正是如此结构:MongoDB的:在阵列
{
_id: 1,
score: [
{
foo: 'a',
bar: 0,
user: {user1: 0, user2: 7}
}
]
}
我需要找到一个至少有一个“分数”(在得分数组元素)的所有文件具有一定的'bar'的值和一个非空'用户'子文档。
这是我想出了(它看起来喜欢它应该工作):
db.col.find({score: {"$elemMatch": {bar:0, user: {"$not":{}} }}})
但是,我得到这个错误:
error: { "$err" : "$not cannot be empty", "code" : 13030 }
任何其他方式做到这一点?
这是*究竟*它是如何构造的?似乎有点偏离。 **> var doc = {score:[foo:'a',bar:0,user:{user1:0,user2:7}]}; Thu Jul 7 00:43:42 SyntaxError:missing]在元素列表(shell)后面:1 ** –
@Justin:你是对的,忘记了数组中的大括号。 – Dmitri