Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-233 CRUD and Interfaces Documentation Chapter
  3. DOCS-468

Mention that insert adds the ObjectId to the object passed in

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

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            gforget Gui Forget
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              11 years, 34 weeks, 2 days ago