我正在尝试使用mongo-java-driver在Java中执行聚合操作.我已经执行了一些其他查找操作,但我无法在Java中正确执行以下聚合:
db.I1.aggregate([
{ "$match": { "ci": 862222} },
{ "$match": { "gi": { "$ne": null } }},
{ "$group": {
"_id": {
"ci": "$ci",
"gi": "$gi",
"gn": "$gn",
"si": "$si"
}
}},
{ "$group": {
"_id": {
"ci": "$_id.ci",
"gi": "$_id.gi",
"gn": "$_id.gn"
},
"sn": { "$sum": 1 }
}},
{ "$sort" : { "_id.gi" : 1}}
])
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几种方法和方法来在Java中执行聚合,但我无法"ci", "gi", "gn","si"在coll.aggregate(asList())方法中正确包含组字段.到目前为止我得到的是以下内容:
MongoCollection<Document> coll = mongo.getCollection("I1");
Document matchCourse = new Document("$match",
new Document("ci", Integer.parseInt(courseid)));
Document matchGroupNotNull = …Run Code Online (Sandbox Code Playgroud)