-
Type: Sub-task
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: mongodb-2.2
-
Component/s: manual
-
Labels:
I was looking for a way to retrieve the ObjectID of the objects being inserted until I found out that it is added automatically to the object I passed to the insert method. This totally makes sense now that I think about it given that the ObjectId is calculated on the client side.I didn't find this mentioned anywhere so I think it should be added to the documentation.
I'm not sure this is working with all the drivers but it does at least for the Java one as this little program shows:
DBCollection testCollection = testDB.getCollection("names");
BasicDBObject newName = new BasicDBObject("name", "joe");
testCollection.insert(newName);
System.out.println(newName);
{ "name" : "joe" , "_id" : { "$oid" : "50402b3a744e0a126a98fe0e"}}