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

_mongoc_client_command_with_opts omits client write concern for findAndModify on 3.2

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • None

      _mongoc_client_command_with_opts() includes the following logic to append the client's write concern:

      /* use default write concern unless it's in opts */
      if ((mode & MONGOC_CMD_WRITE) &&
          server_stream->sd->max_wire_version >=
             WIRE_VERSION_CMD_WRITE_CONCERN &&
          !mongoc_write_concern_is_default (default_wc) &&
          (!opts || !bson_has_field (opts, "writeConcern"))) {
         bson_append_document (&parts.extra,
                               "writeConcern",
                               12,
                               _mongoc_write_concern_get_bson (default_wc));
      }
      

      Before this logic, mongoc_cmd_parts_append_opts() is called. That function has logic to ignore "writeConcern" in opts if the wire version does not support the option. Per the Server Wire version and Feature List, the "writeConcern" option is supported with wire version >= 4 for findAndModify and >= 5 for other commands, which correlate with server versions 3.2+ and 3.4+, respectively.

      The current logic in _mongoc_client_command_with_opts() only applies the client's write concern for wire version >= 5, which means that executing a findAndModify command via one of these helpers (likely read_write_command_with_opts) will omit a write concern on 3.2. This could be relevant for PHPC-834 and PHPLIB once we start using new PHPC methods that wrap these libmongoc functions.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: