Http://stackoverflow.com/questions/3338999/get-id-of-last-inserted-document-in-a-mongodb-w-java-driver
MongoDB API can be implemented, please carefully review the source code of the collection Insert method
A. After inserting a document, you can get the Objectid of the inserted document .Code:Basicdbobject doc = new Basicdbobject ("name", "Matt");
Collection.insert (DOC);
ObjectId id = (ObjectId) doc.get ("_id");
B. Before the document is inserted, you can generate a objectid yourself, the simple way is as followsCode://it ' s safe to do
doc.set ("_id", New ObjectId ())
//if at driver code
if (ensureid && id = = NULL) {
id = objectid.get ();
jo.put ("_id", id);
}
Public static ObjectId get () {
return new ObjectId ();
}See article Link: http://www.thebirdietoldme.com/userActions/thread/Question.aspx?id=3338999http://stackoverflow.com/ Questions/7720256/mongodb-getting-objectid-of-last-inserted-document-with-multiple-concurrent-wr
MongoDB gets the objectid/_id method for the last inserted document