Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查mongodb中的嵌套数组是否全部为空?_Mongodb - Fatal编程技术网

如何检查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