Skip to content

add stub API for client bulk write #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

kevinAlbs
Copy link
Collaborator

Summary

This is a stub to implement the client bulk write API proposed in mongodb/specifications#1534.

This is intended for early feedback, but not to merge.

Rationale

Options

The existing collection bulk write API accepts options in bson_t *opts:

MONGOC_EXPORT (mongoc_bulk_operation_t *)
mongoc_collection_create_bulk_operation_with_opts (
   mongoc_collection_t *collection,
   const bson_t *opts) BSON_GNUC_WARN_UNUSED_RESULT;

The proposed client bulk write API differs. Setter functions are added for improved type safety and editor auto complete:

BSON_EXPORT (void)
mongoc_bulkwriteoptions_set_ordered (mongoc_bulkwriteoptions_t *self, bool ordered);
// ... and other `mongoc_bulkwriteoptions_set_*` setter functions ...

Return

The existing collection bulk write API reports results and error information in a bson_t *reply:

MONGOC_EXPORT (uint32_t)
mongoc_bulk_operation_execute (mongoc_bulk_operation_t *bulk, bson_t *reply, bson_error_t *error);

This PR notably differs. Getter functions are added for improved type safety and editor auto complete:

BSON_EXPORT (int64_t)
mongoc_bulkwriteresult_insertedcount (const mongoc_bulkwriteresult_t *self);
// ... and other `mongoc_bulkwriteresult_*` getter functions ...

Map types are still reported in a bson_t:

// `mongoc_bulkwriteresult_verboseresults` returns a document with the fields: `insertResults`, `updateResult`,
// `deleteResults`. Returns NULL if verbose results were not requested.
BSON_EXPORT (const bson_t *)
mongoc_bulkwriteresult_verboseresults (const mongoc_bulkwriteresult_t *self);

There is no existing convenient representation of map types. I expect needing to interact with verbose results is rare.

Errors are returned in mongoc_bulkwriteexception_t:

// `mongoc_bulkwriteexception_error` sets `error_document` to a document with the fields: `errorLabels`,
// `writeConcernErrors`, `writeErrors`, `errorReplies`.
BSON_EXPORT (void)
mongoc_bulkwriteexception_error (const mongoc_bulkwriteexception_t *self,
                                 bson_error_t *error,
                                 const bson_t **error_document /* May be NULL */);

The maps and lists are reported in the bson_t **error_document.

The mongoc_bulkwriteexception_t can outlive the mongoc_bulkwrite_t. This is intended to enable wrapping languages to wrap mongoc_bulkwriteexception_t when throwing an exception.

@kevinAlbs
Copy link
Collaborator Author

Closing. #1590 proposes an API intended for merging.

@kevinAlbs kevinAlbs closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant