Skip to content

Conversation

@kevinAlbs
Copy link
Collaborator

Motivated by review of https://github.com/10gen/docs-mongodb-internal/pull/15868. This PR intends to update and simplify the CSFLE examples:

  • Remove need for separate include to contain examples in one file.
  • Use scopes to logically separate sections and isolate lifetimes of objects:
bson_t kms_providers;
{
    // Set `local_key` to a 96 byte base64-encoded string.
    const char *local_key =
        "qx/3ydlPRXgUrBvSBWLsllUTaYDcS/pyaVo27qBHkS2AFePjInwhzCmDWHdmCYPmzhO4lRBzeZKFjSafduLL5z5DMvR/"
        "QFfV4zc7btcVmV3QWbDwqZyn6G+Y18ToLHyK";
    char *as_json = bson_strdup_printf(BSON_STR({"local" : {"key" : "%s"}}), local_key);
    init_bson(&kms_providers, &as_json);
    bson_free(as_json);
}
  • Simplify BSON construction. E.g. Use BSON_STR for JSON literals (enables removing quotes):
BSON_STR({"unique" : true, "partialFilterExpression" : {"keyAltNames" : {"$exists" : true}}})
  • Use a FAIL macro to abort on error to simplify error handling.

- Remove C89-isms
- Use scopes to separate logical sections
- Remove need for include to contain examples in one file
- Simplify BSON construction (use BSON_STR. Avoid weirdly formatted BCON)
- Abort on failure to simplify error handling
@kevinAlbs kevinAlbs requested a review from mdb-ad November 13, 2025 18:35
@kevinAlbs kevinAlbs marked this pull request as ready for review November 13, 2025 18:35
@kevinAlbs kevinAlbs requested a review from a team as a code owner November 13, 2025 18:35
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