Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-5945

mongoc_collection_create_indexes_with_opts does not apply write command behavior

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • C Drivers
    • 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

      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:
            Unassigned Unassigned
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: