mongoc_collection_create_indexes_with_opts does not apply write command behavior

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 2.1.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • 🔵 Done
    • C Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary
      mongoc_collection_create_indexes_with_opts uses mongoc_client_command_with_opts rather than mongoc_collection_write_command_with_opts. As a result, write command behavior is not applied:

      • Write concern is not inherited from the parent mongoc_collection_t
      • A server reply with a "writeConcernError" does not result in a failing return.

      Background & Motivation

      mongoc_collection_create_indexes_with_opts documents:

      If no write concern is provided in opts, the collection’s write concern is used.

      That appears untrue. When updating the create_index test function in test-mongoc-opts.c to switch from the deprecated mongoc_collection_create_index_with_opts to mongoc_collection_create_indexes_with_opts, the test failed with:

      $ ./cmake-build/src/libmongoc/test-libmongoc -d --no-fork --match "/inheritance/create_index*"
      
      [...]
      
      Expected: { "createIndexes" : "collection", "writeConcern" : { "w" : "collection" } }
      , Got: { "createIndexes" : "collection", "indexes" : [ { "key" : { "foo" : "bar" }, "name" : "foo_bar" } ], "$db" : "database", "lsid" : { "id" : { "$binary" : { "base64" : "rZ2NhtrGTSKAmjJJzi9Ang==", "subType" : "04" } } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1, "i" : 1 } }, "signature" : { "hash" : { "$binary" : { "base64" : "", "subType" : "00" } }, "keyId" : { "$numberLong" : "6446735049323708417" } }, "operationTime" : { "$timestamp" : { "t" : 1, "i" : 1 } } } }
      , writeConcern: not found
      

      Discovered when removing deprecated mongoc_collection_create_index_with_opts for C driver 2.0.

            Assignee:
            Julia Garland
            Reporter:
            Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: