Skip to content

Commit 7b6ca69

Browse files
jmikolakevinAlbs
authored andcommitted
CDRIVER-3099 specify hint for min/max queries
1 parent 2d7d5f2 commit 7b6ca69

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

src/libmongoc/tests/test-mongoc-collection-find.c

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -575,49 +575,28 @@ test_maxtimems (void)
575575

576576

577577
static void
578-
test_index_spec_modifiers (void)
578+
test_comment (void)
579579
{
580-
/* don't include $max, it needs a slightly different argument to succeed */
581-
const char *modifiers[] = {
582-
"hint",
583-
"min",
584-
};
585-
586-
const char *mod;
587-
size_t i;
588-
char *query;
589-
char *find_command;
590580
test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT;
591-
592-
test_data.expected_result = test_data.docs = "[{'_id': 1}]";
593-
594-
for (i = 0; i < sizeof (modifiers) / sizeof (const char *); i++) {
595-
mod = modifiers[i];
596-
query = bson_strdup_printf ("{'$query': {}, '$%s': {'_id': 1}}", mod);
597-
598-
/* find command has same modifier, without the $-prefix */
599-
find_command = bson_strdup_printf (
600-
"{'find': 'collection', 'filter': {}, '%s': {'_id': 1}}", mod);
601-
602-
test_data.expected_op_query = test_data.query_input = query;
603-
test_data.expected_find_command = find_command;
604-
_test_collection_find (&test_data);
605-
606-
bson_free (query);
607-
bson_free (find_command);
608-
}
581+
test_data.docs = "[{'_id': 1}]";
582+
test_data.query_input = "{'$query': {}, '$comment': 'hi'}";
583+
test_data.expected_op_query = test_data.query_input;
584+
test_data.expected_find_command =
585+
"{'find': 'collection', 'filter': {}, 'comment': 'hi'}";
586+
test_data.expected_result = "[{'_id': 1}]";
587+
_test_collection_find (&test_data);
609588
}
610589

611590

612591
static void
613-
test_comment (void)
592+
test_hint (void)
614593
{
615594
test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT;
616595
test_data.docs = "[{'_id': 1}]";
617-
test_data.query_input = "{'$query': {}, '$comment': 'hi'}";
596+
test_data.query_input = "{'$query': {}, '$hint': { '_id': 1 }}";
618597
test_data.expected_op_query = test_data.query_input;
619598
test_data.expected_find_command =
620-
"{'find': 'collection', 'filter': {}, 'comment': 'hi'}";
599+
"{'find': 'collection', 'filter': {}, 'hint': { '_id': 1 }}";
621600
test_data.expected_result = "[{'_id': 1}]";
622601
_test_collection_find (&test_data);
623602
}
@@ -628,10 +607,29 @@ test_max (void)
628607
{
629608
test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT;
630609
test_data.docs = "[{'_id': 1}]";
631-
test_data.query_input = "{'$query': {}, '$max': {'_id': 100}}";
610+
/* MongoDB 4.2 requires that max/min also use hint */
611+
test_data.query_input =
612+
"{'$query': {}, '$max': {'_id': 100}, '$hint': { '_id': 1 }}";
632613
test_data.expected_op_query = test_data.query_input;
633614
test_data.expected_find_command =
634-
"{'find': 'collection', 'filter': {}, 'max': {'_id': 100}}";
615+
"{'find': 'collection', 'filter': {}, "
616+
"'max': {'_id': 100}, 'hint': { '_id': 1 }}";
617+
test_data.expected_result = "[{'_id': 1}]";
618+
_test_collection_find (&test_data);
619+
}
620+
621+
622+
static void
623+
test_min (void)
624+
{
625+
test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT;
626+
test_data.docs = "[{'_id': 1}]";
627+
/* MongoDB 4.2 requires that max/min also use hint */
628+
test_data.query_input =
629+
"{'$query': {}, '$min': {'_id': 1}, '$hint': { '_id': 1 }}";
630+
test_data.expected_op_query = test_data.query_input;
631+
test_data.expected_find_command = "{'find': 'collection', 'filter': {}, "
632+
"'min': {'_id': 1}, 'hint': { '_id': 1 }}";
635633
test_data.expected_result = "[{'_id': 1}]";
636634
_test_collection_find (&test_data);
637635
}
@@ -1221,11 +1219,10 @@ test_collection_find_install (TestSuite *suite)
12211219
test_framework_skip_if_max_wire_version_more_than_6);
12221220
TestSuite_AddLive (
12231221
suite, "/Collection/find/modifiers/maxtimems", test_maxtimems);
1224-
TestSuite_AddLive (suite,
1225-
"/Collection/find/modifiers/index_spec",
1226-
test_index_spec_modifiers);
12271222
TestSuite_AddLive (suite, "/Collection/find/comment", test_comment);
1223+
TestSuite_AddLive (suite, "/Collection/find/hint", test_hint);
12281224
TestSuite_AddLive (suite, "/Collection/find/max", test_max);
1225+
TestSuite_AddLive (suite, "/Collection/find/min", test_min);
12291226
TestSuite_AddLive (suite, "/Collection/find/modifiers/bool", test_snapshot);
12301227
TestSuite_AddLive (suite, "/Collection/find/showdiskloc", test_diskloc);
12311228
TestSuite_AddLive (suite, "/Collection/find/returnkey", test_returnkey);

0 commit comments

Comments
 (0)