[SERVER-1686] update doesn't add "_id" property when upserting Created: 25/Aug/10 Updated: 25/Aug/10 Resolved: 25/Aug/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Usability |
| Affects Version/s: | 1.6.1 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Mark Waschkowski | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
I think that mongo should populate the "_id" field regardless if a traditional insert is done or a upsert is done. Discussed here: http://groups.google.com/group/mongodb-user/browse_thread/thread/7f986a4609811c1d# Created test case below: import com.google.inject.Guice; public class Test { private static DB db = null; private static String COLLECTION_NAME = "scoring"; public static void main(String[] args) { setup(); testSaveAndRetrieve(); }public static void setup() { Injector injector = Guice.createInjector(new GuiceModuleRiskManagement()); db = injector.getInstance(DB.class); DBCollection col = db.getCollection(COLLECTION_NAME); col.drop(); }public static void testSaveAndRetrieve() { String key = "actionItem"; BasicDBObject dbObject = new BasicDBObject(); dbObject.put("id", key); dbObject.put("test1", "test1 value"); dbObject.put("test2", "test2 value"); dbObject = save(key, dbObject, COLLECTION_NAME); assert(dbObject.get("_id") != null); } public static BasicDBObject save(final String key, final BasicDBObject dbObject, final String collectionName){ Command updateCommand = new Command() { }; /**
public interface Command { public Object execute(); }} |
| Comments |
| Comment by Eliot Horowitz (Inactive) [ 25/Aug/10 ] |
|
See final comment in group discussion. the server does add the _id, but its done server side not client side so you can't access it they way you are doing |