如何检查mongodb中的嵌套数组是否全部为空?
我有以下几点:如何检查mongodb中的嵌套数组是否全部为空?,mongodb,Mongodb,我有以下几点: { "_id" : "1", "firstArray" : [ { "_id" : "11", "secondArray" : [ ] }, { "_id" : "12",
{
"_id" : "1",
"firstArray" : [
{
"_id" : "11",
"secondArray" : [ ]
},
{
"_id" : "12",
"secondArray" : [ ]
},
{
"_id" : "13",
"secondArray" : [ { "type" : "somthing" } ]
}
]
},
{
"_id" : "2",
"firstArray" : [
{
"_id" : "21",
"secondArray" : [ ]
},
{
"_id" : "22",
"secondArray" : [ ]
}
]
}
我需要一个mongodb查询来查找所有嵌套的SecondArray都为空的文档?查询应返回第二个文档,而不是第一个文档 要解决这个问题,我们需要检查arr2的大小,但要启用此功能,我们首先需要解开arr1 请在下面找到解决此问题的聚合框架片段
db.pmoubed.aggregate([{
$unwind : "$firstArray"
}, {
$project : {
_id : 1,
firstArray : 1,
isNotEmpty : {
$size : "$firstArray.secondArray"
}
}
}, {
$group : {
_id : "$_id",
isNotEmpty : {
$sum : "$isNotEmpty"
},
firstArray : {
$push : "$firstArray"
}
}
}, {
$match : {
"isNotEmpty" : 0
}
}
])
欢迎任何评论我得到了以下信息:聚合失败:{“errmsg”:“异常:无效运算符“$size”,代码:15999,“确定”:0}位于src/mongo/shell/collection.js:898您使用的是什么版本的mongo?MongoDB shell版本:2.4.14