Skip to content

Commit 1a1a065

Browse files
committed
CDRIVER-2003 readConcern option should not be included in getMore commands
1 parent 844d288 commit 1a1a065

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

src/mongoc/mongoc-collection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,14 @@ mongoc_collection_aggregate (mongoc_collection_t *collection, /* IN */
457457
mongoc_read_concern_destroy (cursor->read_concern);
458458
cursor->read_concern = mongoc_read_concern_copy (
459459
mongoc_collection_get_read_concern (collection));
460+
461+
if (cursor->read_concern->level != NULL) {
462+
const bson_t *read_concern_bson;
463+
464+
read_concern_bson =
465+
_mongoc_read_concern_get_bson (cursor->read_concern);
466+
BSON_APPEND_DOCUMENT (&command, "readConcern", read_concern_bson);
467+
}
460468
}
461469

462470

src/mongoc/mongoc-cursor.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,6 @@ _mongoc_cursor_run_command (mongoc_cursor_t *cursor,
12651265
read_prefs_result.query_with_read_prefs);
12661266
}
12671267

1268-
if (cursor->read_concern &&
1269-
server_stream->sd->max_wire_version >= WIRE_VERSION_READ_CONCERN) {
1270-
mongoc_read_concern_append (cursor->read_concern,
1271-
read_prefs_result.query_with_read_prefs);
1272-
}
1273-
12741268
ret = mongoc_cluster_run_command_monitored (
12751269
cluster,
12761270
server_stream,

tests/test-mongoc-collection.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,6 +4402,54 @@ test_find_read_concern (void)
44024402
mock_server_destroy (server);
44034403
}
44044404

4405+
static void
4406+
test_getmore_read_concern_live (void *ctx)
4407+
{
4408+
mongoc_client_t *client;
4409+
mongoc_read_concern_t *rc;
4410+
mongoc_collection_t *collection;
4411+
mongoc_cursor_t *cursor;
4412+
mongoc_write_concern_t *wc;
4413+
const bson_t *doc;
4414+
bson_error_t error;
4415+
int i = 0;
4416+
4417+
client = test_framework_client_new ();
4418+
collection = get_test_collection (client, "test_read_concern");
4419+
4420+
rc = mongoc_read_concern_new ();
4421+
mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_LOCAL);
4422+
mongoc_collection_set_read_concern (collection, rc);
4423+
4424+
4425+
wc = mongoc_write_concern_new ();
4426+
mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
4427+
mongoc_collection_set_write_concern (collection, wc);
4428+
4429+
for (i=5000; i > 0; i--) {
4430+
mongoc_collection_insert (collection, MONGOC_INSERT_NONE, tmp_bson
4431+
("{'a': 1}"), NULL, NULL);
4432+
}
4433+
cursor = mongoc_collection_find_with_opts (collection,
4434+
tmp_bson ("{}"),
4435+
NULL,
4436+
NULL);
4437+
4438+
while (mongoc_cursor_next (cursor, &doc)) {
4439+
i++;
4440+
}
4441+
ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error);
4442+
4443+
ASSERT_CMPINT (i, ==, 5000);
4444+
mongoc_cursor_destroy (cursor);
4445+
4446+
mongoc_read_concern_destroy (rc);
4447+
mongoc_write_concern_destroy (wc);
4448+
mongoc_collection_destroy (collection);
4449+
mongoc_client_destroy (client);
4450+
}
4451+
4452+
44054453

44064454
static void
44074455
test_aggregate_read_concern (void)
@@ -4829,6 +4877,9 @@ test_collection_install (TestSuite *suite)
48294877
TestSuite_Add (suite, "/Collection/stats/read_pref", test_stats_read_pref);
48304878
TestSuite_Add (
48314879
suite, "/Collection/find_read_concern", test_find_read_concern);
4880+
TestSuite_AddFull (
4881+
suite, "/Collection/getmore_read_concern_live",
4882+
test_getmore_read_concern_live, NULL, NULL, test_framework_skip_if_max_wire_version_less_than_4);
48324883
TestSuite_AddLive (
48334884
suite, "/Collection/find_and_modify", test_find_and_modify);
48344885
TestSuite_Add (suite,

0 commit comments

Comments
 (0)