Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. DB db = mongo.getDB("yourDbName");
  2. DBCollection coll = db.getCollection("person");
  3.  
  4. DBObject query = new BasicDBObject();
  5. query.put("dateCreated", new BasicDBObject($exists : true));
  6.  
  7. DBCursor cur = coll.find(query).sort(new BasicDBObject("dateCreated", 1)).limit(10);
  8. while(cur.hasNext()) {
  9. DBObject obj = cur.next();
  10. // Get data from the result object here
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement