如何在mongo模板的不同函数中使用DBObject Query只返回count(long)

时间:2016-01-15 07:15:33

标签: java mongodb count distinct long-integer

我有一个独特的查询来从db获取元素列表。 我怎样才能实现这个方法只获得元素的数量 - 第二种方法:

public List distinctElementsByParam(Object param) {
    String collName = mongoOperations.getCollectionName(MyClass.class);
    DBCollection collection = mongoOperations.getCollection(collName);
    BasicDBObject query = new BasicDBObject();
    query.put("mDBField", param);
    return collection.distinct("myDistinctDBField", query);
}
public long distinctCountByParam(Object param) {
    String collName = mongoOperations.getCollectionName(MyClass.class);
    DBCollection collection = mongoOperations.getCollection(collName);
    BasicDBObject query = new BasicDBObject();
    query.put("mDBField", param);
    return ????;
}

0 个答案:

没有答案