MongoDB与Java中的条件不同

Mar*_*syk 3 java spring distinct mongodb

是否有可能使用条件实现MongoDB,如下所示,但是使用Java驱动程序?

db.orders.distinct( 'ord_dt', { price: { $gt: 10 } } )
Run Code Online (Sandbox Code Playgroud)

我尝试过MongoRepository,如下所示

// Enables the distinct flag for the query
List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname);

List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname);
Run Code Online (Sandbox Code Playgroud)

但在我看来,它无法正常工作.我也试过了MongoTemplate

mongoTemplate.getCollection("mycollection").distinct("myfield")
Run Code Online (Sandbox Code Playgroud)

但是没有办法实施条件.知道如何解决这个问题吗?

最好的祝福

Har*_*tel 11

MongoTemplate有内置支持distinctquery:

mongoTemplate.getCollection("collection_name").distinct("field", new BasicDBObject("price", new BasicDBObject("$gt", 10)));