[CXX-1136] collection::find_one_and_* should return result::find_one_and_* objects Created: 18/Nov/16  Updated: 18/Jan/23  Resolved: 18/Jan/23

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: J Rassi Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: bgtrack
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The return type of the collection::find_one_and_*() methods is currently stdx::optional<bsoncxx::document::value>. These methods return a disengaged optional if the "value" field from the findAndModify command response is null; otherwise, they return the document that was returned in "value".

Instead, collection::find_one_and_*() should result objects (i.e. result::find_one_and_*), like the rest of the write methods do. This would be preferable for the following reasons:

  • Consistency with the rest of the write methods.
  • In the case of an upsert operation, the _id of the inserted document could be exposed. Currently, if a k_before find_one_and_update with an upsert is issued and the operation results in an insert, the user does not have access to the _id of the inserted document.
  • The result object could include a manufactured result::bulk_write object. This would allow clients to re-use code to process the result of these operations that was already written to process the result of other write operations.
  • If the server adds any new useful information to the findAndModify command response in the future, this information could be added to the return value without changing the return type of these API methods.


 Comments   
Comment by Rishabh Bisht [ 18/Jan/23 ]

After careful evaluation, we have decided to close this ticket. Please add a comment if the impact of this ticket increases.
Thanks.

Comment by David Golden [ 18/Nov/16 ]

Unfortunately, your proposal is not consistent with the CRUD spec for Find And Modify, which specifies document or null as the return type for those methods (which we model as optional document). Since this change would require a change in the CRUD spec, I suggest opening a SPEC ticket and blocking this ticket on the resolution of that.

Generated at Wed Feb 07 22:01:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.