Skip to content

Commit 5e9fb16

Browse files
committed
CDRIVER-2003 readConcern option should not be included in getMore commands
1 parent 812588c commit 5e9fb16

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

src/mongoc/mongoc-collection.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,16 @@ mongoc_collection_aggregate (mongoc_collection_t *collection, /* IN */
445445

446446
if (!bson_has_field (&command, "readConcern")) {
447447
mongoc_read_concern_destroy (cursor->read_concern);
448-
cursor->read_concern = mongoc_read_concern_copy (mongoc_collection_get_read_concern (collection));
448+
cursor->read_concern = mongoc_read_concern_copy (
449+
mongoc_collection_get_read_concern (collection));
450+
451+
if (cursor->read_concern->level != NULL) {
452+
const bson_t *read_concern_bson;
453+
454+
read_concern_bson =
455+
_mongoc_read_concern_get_bson (cursor->read_concern);
456+
BSON_APPEND_DOCUMENT (&command, "readConcern", read_concern_bson);
457+
}
449458
}
450459

451460

src/mongoc/mongoc-cursor.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,6 @@ _mongoc_cursor_run_command (mongoc_cursor_t *cursor,
12451245
read_prefs_result.query_with_read_prefs);
12461246
}
12471247

1248-
if (cursor->read_concern &&
1249-
server_stream->sd->max_wire_version >= WIRE_VERSION_READ_CONCERN) {
1250-
mongoc_read_concern_append (cursor->read_concern,
1251-
read_prefs_result.query_with_read_prefs);
1252-
}
1253-
12541248
ret = mongoc_cluster_run_command_monitored (
12551249
cluster,
12561250
server_stream,

tests/test-mongoc-collection.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,6 +4227,54 @@ test_find_read_concern (void)
42274227
mock_server_destroy (server);
42284228
}
42294229

4230+
static void
4231+
test_getmore_read_concern_live (void *ctx)
4232+
{
4233+
mongoc_client_t *client;
4234+
mongoc_read_concern_t *rc;
4235+
mongoc_collection_t *collection;
4236+
mongoc_cursor_t *cursor;
4237+
mongoc_write_concern_t *wc;
4238+
const bson_t *doc;
4239+
bson_error_t error;
4240+
int i = 0;
4241+
4242+
client = test_framework_client_new ();
4243+
collection = get_test_collection (client, "test_read_concern");
4244+
4245+
rc = mongoc_read_concern_new ();
4246+
mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_LOCAL);
4247+
mongoc_collection_set_read_concern (collection, rc);
4248+
4249+
4250+
wc = mongoc_write_concern_new ();
4251+
mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
4252+
mongoc_collection_set_write_concern (collection, wc);
4253+
4254+
for (i=5000; i > 0; i--) {
4255+
mongoc_collection_insert (collection, MONGOC_INSERT_NONE, tmp_bson
4256+
("{'a': 1}"), NULL, NULL);
4257+
}
4258+
cursor = mongoc_collection_find_with_opts (collection,
4259+
tmp_bson ("{}"),
4260+
NULL,
4261+
NULL);
4262+
4263+
while (mongoc_cursor_next (cursor, &doc)) {
4264+
i++;
4265+
}
4266+
ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error);
4267+
4268+
ASSERT_CMPINT (i, ==, 5000);
4269+
mongoc_cursor_destroy (cursor);
4270+
4271+
mongoc_read_concern_destroy (rc);
4272+
mongoc_write_concern_destroy (wc);
4273+
mongoc_collection_destroy (collection);
4274+
mongoc_client_destroy (client);
4275+
}
4276+
4277+
42304278

42314279
static void
42324280
test_aggregate_read_concern (void)
@@ -4600,6 +4648,9 @@ test_collection_install (TestSuite *suite)
46004648
TestSuite_AddLive (suite, "/Collection/find_and_modify", test_find_and_modify);
46014649
TestSuite_Add (suite, "/Collection/find_and_modify/write_concern",
46024650
test_find_and_modify_write_concern_wire_32);
4651+
TestSuite_AddFull (suite, "/Collection/getmore_read_concern_live",
4652+
test_getmore_read_concern_live, NULL, NULL,
4653+
test_framework_skip_if_max_wire_version_less_than_4);
46034654
TestSuite_Add (suite, "/Collection/find_and_modify/write_concern_pre_32",
46044655
test_find_and_modify_write_concern_wire_pre_32);
46054656
TestSuite_AddFull (suite, "/Collection/large_return", test_large_return, NULL, NULL, test_framework_skip_if_slow_or_live);

0 commit comments

Comments
 (0)