-
Notifications
You must be signed in to change notification settings - Fork 94
Description
The Java driver (using 4.1.12) only allows setting the key, but not the id of a document.
This is cumbersome in situations where I want to override a document in the DB but keeping the same ID and key, e.g. during a full update (avoiding having to override every single property).
I know it is possible to update a document that has aNULL _id and a key, then db.collection(collectionName).updateDocument(baseObject.getKey(), baseObject, UPDATE_OPTIONS) will work fine and take the ID from the key, as expected.
However this makes writing code for transparently upserting documents cumbersome, because in the case of a clone operation, I cannot follow the usual logic that a document without an ID does not exist and needs an insert - because the Java driver does not allow me to copy the ID of the old document in my clone - so I need a special case for that and implement the update myself, or else I run into a wrong INSERT and the driver of course fails because the document with that ID already exists.
Proposed solution:
- provide a method to set the ID in a document and/or
- provide a single
upsertmethod that does the UPSERT logic we all know and love