-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.10.1
-
Component/s: Documentation, Query Operations
-
None
The javadocs for both the MongoCollection #updateOne and #findOneAndUpdate methods both state for the 'update' param:
@param update a document describing the update, which may not be null. The update to apply must include only update operators.
Perhaps this should also include information about passing in a replacement document instead of an just an update document that contains update operators.
I could not find this document anywhere, but if I pass in an empty document to the update parameter, mongo will replace the existing document with that empty document. I assume that because the empty document contains no update operators it is treated a name/value paired object? I would have thought that passing an empty document would result in no changes the existing document, as it does actually not contain any fields.
Also, when dynamically constructing a Bson update object using the Updates.combine method, if at least one update operator is not added it will be considered an invalid update because it does not contain any update operators. Is it possible to treat the empty array that would be created by the Updates.combine method as a valid update operator that essentially does nothing instead of throwing an error?
As it stands, the update parameter cannot be null (which seems somewhat inconsistent with the other Bson params that are nullable), and we cannot pass an empty array of updates either.