_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.
- is related to
-
CDRIVER-2408 Fix documentation for command_with_opts functions and aggregate
- Closed
-
PHPC-834 Add Read, ReadWrite, and Write command execute methods
- Closed