I am using MongoDB via Java Driver (Spring Data MongoDB). Now my code is like:
DBObject query = new BasicDBObject("user", user);
mongoTemplate.getCollection("reports").distinct("category", query);
Right now, the result list is not ordered. I want to it sorting by a ASC order. I have check this question Query MongoDB for ordered distinct values but I only get the answer which order the list by java side. How to order the result in MongoDB side?
I don't think you can use the Distinct command with a "sort" parameter with standard queries.
However, you can use the aggregation framework to do these more complex queries.