-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Major - P3
-
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 )
}
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().