[CDRIVER-637] Implement CRUD API spec Created: 06/May/15  Updated: 03/May/17  Resolved: 03/Feb/17

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

Type: New Feature Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-220 Implement CRUD API spec Closed

 Comments   
Comment by A. Jesse Jiryu Davis [ 03/Feb/17 ]

We'd need to add batchSize and useCursor to "aggregate" and deprecate "cursor". Add a new function to execute "distinct". Add a cursorType option to "find" that overrides tailable and await options.

The "bulkWrite" function takes 6 different WriteModel structs, each of which requires a creator and destructor, and a total of 19 setter methods. In all, 36 new functions.

Regular writes, insertOne insertMany deleteOne deleteMany replaceOne updateOne and updateMany, along with their 4 different options structs, a creator and destructor for each option struct and a total of 7 setters for opts and 18 getters for result fields, totals 44 new functions.

The findAndModify helpers findOneAndDelete, findOneAndReplace, findOneAndUpdate, along with options structs and 18 setters, totals 24 new functions. We'd deprecate our two existing findAndModify functions and the dozen functions for find_and_modify_opts_t.

No one from Customer Support, Docs, or external has asked us to do this. Neither has anyone within Drivers team implementing C++ or PHP wrappers. The benefits are only theoretical.

New API will be more verbose, error-prone, and slow compared to old one:

/* old */
r = mongoc_collection_update (collection, MONGOC_UPDATE_UPSERT, &filter, &update, NULL, NULL);
 
/* new */
mongoc_update_opts_t *opts;
 
opts = mongoc_update_opts_new ();
mongoc_update_opts_set_upsert (opts, true);
r = mongoc_collection_update_one (collection, &filter, &update, opts);
mongoc_update_opts_destroy (opts);

Because this API is not well-suited to C, we have to add 100 or more new functions and dozens of new structs, at least. We can never delete them after this. New functions require work, will have bugs, and will further clutter our API docs, which will confuse future users asking "just tell me how to insert a document".

We could mitigate the extra number of functions by deprecating and deleting some of the functions we replaced, e.g. mongoc_collection_insert. That's a bad idea because if we delete those functions in the C Driver 2.0, then people will have to change large amounts of code in order to upgrade. They won't upgrade and we'll be stuck maintaining two drivers.

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