Created
July 6, 2019 17:56
-
-
Save shamilnabiyev/942122aeb47e0f0e85c549d14c95cda5 to your computer and use it in GitHub Desktop.
Java MongoDB Driver, sort by date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB db = mongo.getDB("yourDbName"); | |
DBCollection coll = db.getCollection("person"); | |
DBObject query = new BasicDBObject(); | |
query.put("dateCreated", new BasicDBObject($exists : true)); | |
DBCursor cur = coll.find(query).sort(new BasicDBObject("dateCreated", 1)).limit(10); | |
while(cur.hasNext()) { | |
DBObject obj = cur.next(); | |
// Get data from the result object here | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment