Thursday, August 14, 2014

MongoDB Sorting

Mongo DB command line:
db.collection.find().sort( { score: -1 } )

Mongo DB Java driver:
DBCursor cursor = collection.find();
cursor.sort(new BasicDBObject("score", -1));

Note that "-1" has to be an int, not a String

Reference: http://docs.mongodb.org/manual/reference/operator/meta/orderby/

No comments:

Post a Comment