[JAVA-3258] Inconsistent javadoc documentation for MongoCollection #updateOne and #findOneAndUpdate methods. Created: 05/Apr/19  Updated: 28/Oct/23  Resolved: 03/Aug/19

Status: Closed
Project: Java Driver
Component/s: Documentation, Query Operations
Affects Version/s: 3.10.1
Fix Version/s: 3.11.0

Type: Improvement Priority: Major - P3
Reporter: Eric Tray Assignee: John Stewart (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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.

 

 



 Comments   
Comment by Githook User [ 03/Aug/19 ]

Author:

{'name': 'John Stewart', 'email': 'john.stewart@mongodb.com', 'username': 'jstewart-mongo'}

Message: Update documentation for MongoCollection#updateOne and MongoCollection#findOneAndUpdate

JAVA-3258
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/f78425f23b84632e3a6de1571b731ad90fd741dc

Generated at Thu Feb 08 08:59:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.