Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-258

Need oid in WriteResult

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • 2.5
    • Affects Version/s: 2.4
    • Component/s: None
    • None

      Today if I insert or upsert a record and I want the oid for what was just inserted I have to look at the modified object.
      But... I wrap these calls and usually return the WriteResult in case of an error. So its not easy to get to the oid in that case.
      If the oid were included in WriteResult, with some kind of accessor, this would solve my problem.

      In other words if I have a Storage object that has a save() method. I pass in serialized json to save().

      public class Storage {
      public WriteResult save( String jsonObj )

      { DBObject dbo = com.mongodb.util.JSON.parse(jsonObj); return mydbcollection.insert(...) }

      }

      The DBObject is created in save() so the caller never has access to it. My save() returns a WriteResult to check for errors. The modified _id that would be updated in my DBObject is lost when I return from save(). I could return some kind of tuple of (WriteResult, _id), but that's code smell. IMHO, a better option is to have WriteResult provide access to the _id--and I know it has it because it prints out in WriteResult.toString().

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            gzoller Greg Zoller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: