Inserting Documents in MongoDB From Java
To insert an object into MongoDB, you create it and then invoke the insert() method on the DBCollection into which it has to be pushed into.
https://gist.github.com/nofatclips/5637783
The output shows that the driver added an ID field upon the call:
{ "site" : "nofatclips.com" , "author" : "DeK"} { "site" : "nofatclips.com" , "author" : "DeK" , "_id" : { "$oid" : "519e4cdb04089e005378ac14"}}
The ID can also be added explicitly, as a new instance of ObjectId:
doc.put("_id", new ObjectId());











