Thursday, September 6, 2012

MongoDB: Get ID of Inserted Document

After inserting, use the following:

DBObject dbObj = new BasicDBObject(valuesMap);
collection.insert(dbObj);
ObjectId id = (ObjectId)dbObj.get("_id");

No comments:

Post a Comment