[CDRIVER-2410] _mongoc_client_command_with_opts omits client write concern for findAndModify on 3.2 Created: 27/Nov/17  Updated: 28/Oct/23  Resolved: 05/Dec/17

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.9.0

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-2408 Fix documentation for command_with_op... Closed
is related to PHPC-834 Add Read, ReadWrite, and Write comman... Closed

 Description   

_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.



 Comments   
Comment by Githook User [ 05/Dec/17 ]

Author:

{'username': 'ajdavis', 'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis'}

Message: CDRIVER-2410 findAndModify writeConcern as cmd_with_opts

If mongoc_client_read_write_command_with_opts or similar function is
passed a "findAndModify" command with no write concern and wire version
>= 4, use the client, database, or collection write concern.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/bd7133dba9cf5c75ba654e4255495c5f97d07bdb

Comment by Jeremy Mikola [ 04/Dec/17 ]

jesse: I don't recall if we discussed it, but this would also make a fine low-hanging-fruit ticket for one of the new grads.

Comment by A. Jesse Jiryu Davis [ 04/Dec/17 ]

jmikola I can't remember: do you plan to do this, or shall I?

Comment by Jeremy Mikola [ 27/Nov/17 ]

Related to documentation changes in CDRIVER-2408.

The docs for the various command_with_opts functions previously stated "The write concern is omitted for MongoDB before 3.2" and I was in the process of changing that to "The write concern is omitted for MongoDB before 3.4 (or 3.2 for "findAndModify")".

Without this issue, the correct documentation would need to be: "The write concern in opts is ignored for MongoDB before 3.4 (or 3.2 for "findAndModify"). The write concern from client is ignored for MongoDB before 3.4."

Generated at Wed Feb 07 21:15:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.