Investigate changes in CDRIVER-6180: Deprecate bson_append_array_begin

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: Unknown
    • 2.3.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Proposal

      Deprecate bson_append_array_begin and BSON_APPEND_ARRAY_BEGIN

      Background & Motivation
      Some libbson array building APIs make it easy to construct an array with invalid keys:

      bson_t doc = BSON_INITIALIZER, subarray;
      BSON_APPEND_ARRAY_BEGIN(&doc, "array", &subarray);
      BSON_APPEND_UTF8(&subarray, "1", "foo"); // Oops! Should be "0".
      bson_append_array_end (&doc, &subarray);
      

      BSON arrays are expected to have sequential keys "0", "1", "2", ...

      bson_array_builder_t provides a safer alternative to creating BSON arrays in libbson:

      bson_t doc = BSON_INITIALIZER;
      bson_array_builder_t *builder;
      BSON_APPEND_ARRAY_BUILDER_BEGIN(&doc, "array", &builder);
      bson_array_builder_append_utf8(builder, "foo", -1);
      bson_append_array_builder_end(&doc, builder);

       

      Note: use `bson_append_array_unsafe_begin` instead as per Kevin's comment

            Assignee:
            Jérôme Tamarelle
            Reporter:
            Service Account: DBX TPM
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: