Blog Archives

Getting Date information from MongoDB’s document objectid

This post is for mongodb java api only.


	private Date getTimeStampFromID() {
        DB db = connectDB();
        DBCollection collection = db.getCollectionFromString("database");
		DBCursor cursor = collection.find();
		while(cursor.hasNext()){
			return (new Date(((ObjectId)cursor.next().get(TAG_ID)).getTime()));
		}
	}

Advertisements