MongoDB Java driver: distinct with sort
Using the MongoDB console I can write a native MongoDB query using
distinct key with a sort like this:
db.mycollection.distinct('mykey').sort('mykey', 1)
Using the Java driver I would expect to be able to write the same query
like this:
myCollection.distinct("myKey").sort(new BasicDBObject("myKey", 1));
However, this doesn't work because DBCollection#distinct() returns type
List and not type DBCursor like DBCollection#find().
How can I write the distinct query with a sort using the Java driver?
No comments:
Post a Comment