我想知道是否可以使用MongoDB Java驱动程序在子字段上执行GroupCommand。我不知道如何在第三个参数中表达它。
MongoDB.use(DefaultMongoIdentifier) { db =>
var collection = db.getCollection(collectionName)
var cmd = new GroupCommand(collection,
null,
new BasicDBObject("items", new BasicDBObject("field", 1)),
new BasicDBObject("count", 0),
"function ( curr, result ) {result.count++}",
null);
implicit val formats = net.liftweb.json.DefaultFormats
println(JObjectParser.serialize(collection.group(cmd)).extract[List[Map[String, String]]])
JObjectParser.serialize(collection.group(cmd)).extract[List[Map[String, String]]]
}