CRUD and Interfaces Documentation Chapter (DOCS-233)

[DOCS-468] Mention that insert adds the ObjectId to the object passed in Created: 31/Aug/12  Updated: 30/Oct/23  Resolved: 12/Oct/12

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: mongodb-2.2
Fix Version/s: Server_Docs_20231030

Type: Sub-task Priority: Minor - P4
Reporter: Gui Forget Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: newwriter
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 11 years, 18 weeks, 5 days ago

 Description   

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"}}



 Comments   
Comment by auto [ 12/Oct/12 ]

Author:

{u'date': u'2012-10-12T13:48:43-07:00', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-468 adding additional clarification
Branch: master
https://github.com/mongodb/docs/commit/063eb9b2b64351d67044d90052c7451f27655331

Comment by auto [ 12/Oct/12 ]

Author:

{u'date': u'2012-10-12T12:16:05-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: merge: DOCS-468
Branch: master
https://github.com/mongodb/docs/commit/fb68f8cb9974d16f7704e7c1dee01667781aec4b

Comment by auto [ 12/Oct/12 ]

Author:

{u'date': u'2012-10-12T10:54:52-07:00', u'email': u'kay.kim@10gen.com', u'name': u'kay'}

Message: DOCS-468 CRUD drafts
Branch: master
https://github.com/mongodb/docs/commit/f5613178de240fb5f8cbd36d6ed2c23109a26dd8

Comment by Sam Kleinman (Inactive) [ 28/Sep/12 ]

for the insert section of the crud chapter

Generated at Thu Feb 08 07:38:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.