Skip to content

Commit 5602c58

Browse files
committed
CDRIVER-2517 ignore $gleStats creating cursor from command reply
1 parent afc62d1 commit 5602c58

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/mongoc/mongoc-cursor.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,8 +2244,14 @@ mongoc_cursor_new_from_command_reply (mongoc_client_t *client,
22442244
BSON_ASSERT (client);
22452245
BSON_ASSERT (reply);
22462246

2247-
bson_copy_to_excluding_noinit (
2248-
reply, &opts, "cursor", "ok", "operationTime", "$clusterTime", NULL);
2247+
bson_copy_to_excluding_noinit (reply,
2248+
&opts,
2249+
"cursor",
2250+
"ok",
2251+
"operationTime",
2252+
"$clusterTime",
2253+
"$gleStats",
2254+
NULL);
22492255

22502256
cursor = _mongoc_cursor_new_with_opts (
22512257
client, NULL, true /* is_find */, NULL, &opts, NULL, NULL);

tests/test-mongoc-cursor.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,43 @@ test_cursor_new_tailable_await (void)
727727
}
728728

729729

730+
static void
731+
test_cursor_new_ignores_fields (void)
732+
{
733+
mock_server_t *server;
734+
mongoc_client_t *client;
735+
mongoc_cursor_t *cursor;
736+
bson_error_t error;
737+
738+
server = mock_server_with_autoismaster (WIRE_VERSION_FIND_CMD);
739+
mock_server_run (server);
740+
741+
client = mongoc_client_new_from_uri (mock_server_get_uri (server));
742+
cursor = mongoc_cursor_new_from_command_reply (
743+
client,
744+
bson_copy (tmp_bson ("{'ok': 1,"
745+
" 'cursor': {"
746+
" 'id': 0,"
747+
" 'ns': 'test.foo',"
748+
" 'firstBatch': []"
749+
" },"
750+
" 'operationTime' : {},"
751+
" '$clusterTime': {},"
752+
" '$gleStats': {},"
753+
" 'batchSize': 10"
754+
"}")),
755+
0);
756+
757+
ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error);
758+
759+
ASSERT_MATCH (&cursor->opts, "{'batchSize': 10}");
760+
761+
mongoc_cursor_destroy (cursor);
762+
mongoc_client_destroy (client);
763+
mock_server_destroy (server);
764+
}
765+
766+
730767
static void
731768
test_cursor_new_invalid_filter (void)
732769
{
@@ -1673,6 +1710,8 @@ test_cursor_install (TestSuite *suite)
16731710
TestSuite_AddLive (suite, "/Cursor/new_invalid", test_cursor_new_invalid);
16741711
TestSuite_AddMockServerTest (
16751712
suite, "/Cursor/new_tailable_await", test_cursor_new_tailable_await);
1713+
TestSuite_AddMockServerTest (
1714+
suite, "/Cursor/new_ignores_fields", test_cursor_new_ignores_fields);
16761715
TestSuite_AddLive (
16771716
suite, "/Cursor/new_invalid_filter", test_cursor_new_invalid_filter);
16781717
TestSuite_AddLive (

0 commit comments

Comments
 (0)