driver-legacy/src/main/com/mongodb/GroupCommand.java
public DBObject toDBObject() {
        DBObject args = new BasicDBObject("ns", collectionName).append("cond", condition)
                                                               .append("$reduce", reduce)
                                                               .append("initial", initial);

        if (keys != null) {
            args.put("key", keys);
        }

        if (keyf != null) {
            args.put("$keyf", keyf);
        }

        if (finalize != null) {
            args.put("finalize", finalize);
        }
        return new BasicDBObject("group", args);
    }
public DBObject toDBObject() {
        DBObject args = new BasicDBObject("ns", collectionName).append("cond", condition)
                                                               .append("$reduce", reduce)
                                                               .append("initial", initial);

        if (keys != null) {
            args.put("key", keys);
        }

        if (keyf != null) {
            args.put("$keyf", keyf);
        }

        if (finalize != null) {
            args.put("finalize", finalize);
        }
        return new BasicDBObject("group", args);
    }
Turns this group command into the DBObject format of the command.

@return a DBObject containing the group command as a MongoDB document