[CDRIVER-4306] Inconsistencies between update, delete, and insert CRUD functions Created: 10/Mar/22  Updated: 28/Mar/23

Status: Backlog
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: FY24Q4, neweng, rb-track
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

While implementing support for let in CDRIVER-4198, I realized that there are various differences to how _mongoc_collection_update_or_replace and _mongoc_delete_one_or_many are implemented. Both of those functions are the common helpers for their respective CRUD methods.

A few, but not all, inconsistencies are as follows:

  • _mongoc_delete_one_or_many is missing the "collection" prefix found on the update/replace helper.
  • The delete_one and delete_many methods pass an initialized bson_t as a limit parameter, which is the used to append individual options for the delete statement and later passed as the opts parameter _mongoc_write_command_init_delete_idl. That document is later destroyed in the corresponding public CRUD method. In _mongoc_collection_update_or_replace, the equivalent structure exists entirely within the helper method.
  • _mongoc_delete_one_or_many asserts that the incoming bson_t *reply is empty or null. No such assertion is made in the update helper.
  • _mongoc_collection_update_or_replace checks that an explicit write concern is not being used within a transaction, while _mongoc_delete_one_or_many has no such check.
  • _mongoc_delete_one_or_many receives extra opts (from mongoc_delete_one_opts_t and mongoc_delete_many_opts_t) and passes those as the cmd_opts parameter to _mongoc_write_command_init_delete_idl. In _mongoc_collection_update_or_replace, the extra opts are used to append options for the update statement and later passed as the opts parameter to _mongoc_write_command_init_update_idl (akin to how the limit document in the delete methods is used).

Of these inconsistencies, I believe only the transaction error checking is relevant to users. The other issues seem mostly internal, but could improve maintainability if addressed.



 Comments   
Comment by Jeremy Mikola [ 29/Apr/22 ]

Modifying the issue description as I also noticed the insert_one and insert_many methods also handle extra options and pass them along to _mongoc_write_command_init_insert_idl as cmd_opts.

Generated at Wed Feb 07 21:20:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.