Skip to content

Commit c2639c8

Browse files
committed
CDRIVER-2273 omit default write concern from CRUD commands
1 parent 550438a commit c2639c8

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/mongoc/mongoc-write-command.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
* - Remove error parameter to ops, favor result->error.
3333
*/
3434

35-
#define WRITE_CONCERN_DOC(wc) \
36-
(wc) ? (_mongoc_write_concern_get_bson ((mongoc_write_concern_t *) (wc))) \
37-
: (&gEmptyWriteConcern)
38-
3935
typedef void (*mongoc_write_op_t) (mongoc_write_command_t *command,
4036
mongoc_client_t *client,
4137
mongoc_server_stream_t *server_stream,
@@ -46,8 +42,6 @@ typedef void (*mongoc_write_op_t) (mongoc_write_command_t *command,
4642
bson_error_t *error);
4743

4844

49-
static bson_t gEmptyWriteConcern = BSON_INITIALIZER;
50-
5145
/* indexed by MONGOC_WRITE_COMMAND_DELETE, INSERT, UPDATE */
5246
static const char *gCommandNames[] = {"delete", "insert", "update"};
5347
static const char *gCommandFields[] = {"deletes", "documents", "updates"};
@@ -292,8 +286,12 @@ _mongoc_write_command_init (bson_t *doc,
292286
}
293287

294288
BSON_APPEND_UTF8 (doc, gCommandNames[command->type], collection);
295-
BSON_APPEND_DOCUMENT (
296-
doc, "writeConcern", WRITE_CONCERN_DOC (write_concern));
289+
if (write_concern && !mongoc_write_concern_is_default (write_concern)) {
290+
BSON_APPEND_DOCUMENT (doc,
291+
"writeConcern",
292+
_mongoc_write_concern_get_bson (
293+
(mongoc_write_concern_t *) (write_concern)));
294+
}
297295
BSON_APPEND_BOOL (doc, "ordered", command->flags.ordered);
298296

299297
if (command->flags.bypass_document_validation !=

tests/test-mongoc-bulk.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,25 @@ test_bulk_error_unordered (void)
282282

283283
future = future_bulk_operation_execute (bulk, &reply, &error);
284284

285-
request = mock_server_receives_command (
286-
mock_server,
287-
"test",
288-
MONGOC_QUERY_NONE,
289-
"{ 'update' : 'test', 'writeConcern' : { }, 'ordered' : false }",
290-
NULL);
285+
request =
286+
mock_server_receives_command (mock_server,
287+
"test",
288+
MONGOC_QUERY_NONE,
289+
"{'update': 'test',"
290+
" 'writeConcern': {'$exists': false},"
291+
" 'ordered': false}",
292+
NULL);
291293
mock_server_replies_simple (request, "{ 'ok' : 1, 'n' : 5 }");
292294

293295
request_destroy (request);
294-
request = mock_server_receives_command (
295-
mock_server,
296-
"test",
297-
MONGOC_QUERY_NONE,
298-
"{ 'update' : 'test', 'writeConcern' : { }, 'ordered' : false }",
299-
NULL);
296+
request =
297+
mock_server_receives_command (mock_server,
298+
"test",
299+
MONGOC_QUERY_NONE,
300+
"{'update': 'test',"
301+
" 'writeConcern': {'$exists': false},"
302+
" 'ordered': false}",
303+
NULL);
300304

301305
request_destroy (request);
302306
mock_server_destroy (mock_server);
@@ -2660,7 +2664,7 @@ _test_wtimeout_plus_duplicate_key_err (void)
26602664
"test",
26612665
MONGOC_QUERY_NONE,
26622666
"{'insert': 'test',"
2663-
" 'writeConcern': {},"
2667+
" 'writeConcern': {'$exists': false},"
26642668
" 'ordered': false,"
26652669
" 'documents': [{'_id': 1}, {'_id': 2}]}");
26662670

@@ -2681,7 +2685,7 @@ _test_wtimeout_plus_duplicate_key_err (void)
26812685
"test",
26822686
MONGOC_QUERY_NONE,
26832687
"{'delete': 'test',"
2684-
" 'writeConcern': {},"
2688+
" 'writeConcern': {'$exists': false},"
26852689
" 'ordered': false,"
26862690
" 'deletes': [{'q': {'_id': 3}, 'limit': 0}]}");
26872691

0 commit comments

Comments
 (0)