Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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 Java驱动程序聚合字符串_Mongodb_Mongodb Java - Fatal编程技术网

MongoDB Java驱动程序聚合字符串

MongoDB Java驱动程序聚合字符串,mongodb,mongodb-java,Mongodb,Mongodb Java,我得到一个结构为JSONArray[{abc:123},{def:456}]的字符串,我需要使用它来调用mongoCollection.aggregatetheString 聚合函数takes List我能想到这个,但它看起来有点难看 JSONArray array = new JSONArray(theString); List<Document> list = new ArrayList<>(); for(Object

我得到一个结构为JSONArray[{abc:123},{def:456}]的字符串,我需要使用它来调用mongoCollection.aggregatetheString


聚合函数takes List我能想到这个,但它看起来有点难看

        JSONArray array = new JSONArray(theString);
        List<Document> list = new ArrayList<>();
        for(Object jsonObject : jsonArray){
            Document document = Document.parse(jsonObject.toString());
            list.add(document);
        }
        collection.aggregate(list);