如何将mongodb查询转换为java

时间:2016-10-08 07:57:47

标签: java mongodb-java

如何将mongodb查询转换为java

我想将以下查询转换为java

db.Student.aggregate( {$group : {_id : "$prnno", x: {$push:"$name"} , st:{$push: "$per"} }},
                      {$sort:{st:-1} },{$limit:3});

1 个答案:

答案 0 :(得分:0)

尝试这个,我希望它有所帮助:

collection.aggregate(Arrays.asList({$or:[
        new BasicDBObject("$match", new BasicDBObject("x", {$push:"$name"})),
        new BasicDBObject("$match", new BasicDBObject("st", {$push: "$per"}))],
        new BasicDBObject("$sort", new BasicDBObject("st", -1)),
        new BasicDBObject("$limit", 3)))