@@ -176,6 +176,7 @@ _test_collection_op_query_or_find_command (
176
176
mongoc_client_t * client ;
177
177
mongoc_collection_t * collection ;
178
178
mongoc_cursor_t * cursor ;
179
+ bson_error_t error ;
179
180
future_t * future ;
180
181
request_t * request ;
181
182
const bson_t * doc ;
@@ -198,6 +199,7 @@ _test_collection_op_query_or_find_command (
198
199
test_data -> fields_bson ,
199
200
test_data -> read_prefs );
200
201
202
+ ASSERT_OR_PRINT (!mongoc_cursor_error (cursor , & error ), error );
201
203
future = future_cursor_next (cursor , & doc );
202
204
request = check_request_fn (server , test_data );
203
205
ASSERT (request );
@@ -388,6 +390,22 @@ test_dollar_query (void)
388
390
}
389
391
390
392
393
+ static void
394
+ test_dollar_or (void )
395
+ {
396
+ test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT ;
397
+
398
+ test_data .docs = "[{'_id': 1}, {'_id': 2}, {'_id': 3}]" ;
399
+ test_data .query_input = "{'$or': [{'_id': 1}, {'_id': 3}]}" ;
400
+ test_data .expected_op_query = test_data .query_input ;
401
+ test_data .expected_find_command =
402
+ "{'find': 'collection', 'filter': {'$or': [{'_id': 1}, {'_id': 3}]}}" ;
403
+
404
+ test_data .expected_result = "[{'_id': 1}, {'_id': 3}]" ;
405
+ _test_collection_find (& test_data );
406
+ }
407
+
408
+
391
409
/* test that we can query for a document by a key named "filter" */
392
410
static void
393
411
test_key_named_filter (void )
@@ -526,40 +544,6 @@ test_int_modifiers (void)
526
544
}
527
545
528
546
529
- static void
530
- test_bool_modifiers (void )
531
- {
532
- const char * modifiers [] = {
533
- "snapshot" ,
534
- "showRecordId" ,
535
- };
536
-
537
- const char * mod ;
538
- size_t i ;
539
- char * query ;
540
- char * find_command ;
541
- test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT ;
542
-
543
- test_data .expected_result = test_data .docs = "[{'_id': 1}]" ;
544
-
545
- for (i = 0 ; i < sizeof (modifiers ) / sizeof (const char * ); i ++ ) {
546
- mod = modifiers [i ];
547
- query = bson_strdup_printf ("{'$query': {}, '$%s': true}" , mod );
548
-
549
- /* find command has same modifier, without the $-prefix */
550
- find_command = bson_strdup_printf (
551
- "{'find': 'collection', 'filter': {}, '%s': true}" , mod );
552
-
553
- test_data .expected_op_query = test_data .query_input = query ;
554
- test_data .expected_find_command = find_command ;
555
- _test_collection_find (& test_data );
556
-
557
- bson_free (query );
558
- bson_free (find_command );
559
- }
560
- }
561
-
562
-
563
547
static void
564
548
test_index_spec_modifiers (void )
565
549
{
@@ -621,6 +605,19 @@ test_max (void)
621
605
}
622
606
623
607
608
+ static void
609
+ test_snapshot (void )
610
+ {
611
+ test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT ;
612
+ test_data .docs = "[{'_id': 1}]" ;
613
+ test_data .query_input = "{'$query': {}, '$snapshot': true}" ;
614
+ test_data .expected_op_query = test_data .query_input ;
615
+ test_data .expected_find_command = "{'find': 'collection', 'filter': {}, 'snapshot': true}" ;
616
+ test_data .expected_result = "[{'_id': 1}]" ;
617
+ _test_collection_find (& test_data );
618
+ }
619
+
620
+
624
621
/* $showDiskLoc becomes showRecordId */
625
622
static void
626
623
test_diskloc (void )
@@ -690,6 +687,21 @@ test_limit (void)
690
687
}
691
688
692
689
690
+ static void
691
+ test_unrecognized_dollar_option (void )
692
+ {
693
+ test_collection_find_t test_data = TEST_COLLECTION_FIND_INIT ;
694
+
695
+ test_data .query_input = "{'$query': {'a': 1}, '$dumb': 1}" ;
696
+ test_data .expected_find_command =
697
+ "{'find': 'collection', 'filter': {'a': 1}, '$dumb': 1}" ;
698
+
699
+ test_data .requires_wire_version_4 = true;
700
+ test_data .do_live = false;
701
+ _test_collection_find (& test_data );
702
+ }
703
+
704
+
693
705
static void
694
706
test_query_flags (void )
695
707
{
@@ -968,6 +980,8 @@ test_collection_find_install (TestSuite *suite)
968
980
{
969
981
TestSuite_Add (suite , "/Collection/find/dollar_query" ,
970
982
test_dollar_query );
983
+ TestSuite_Add (suite , "/Collection/find/dollar_or" ,
984
+ test_dollar_or );
971
985
TestSuite_Add (suite , "/Collection/find/key_named_filter" ,
972
986
test_key_named_filter );
973
987
TestSuite_Add (suite , "/Collection/find/cmd/subdoc_named_filter" ,
@@ -984,14 +998,14 @@ test_collection_find_install (TestSuite *suite)
984
998
test_fields );
985
999
TestSuite_Add (suite , "/Collection/find/modifiers/integer" ,
986
1000
test_int_modifiers );
987
- TestSuite_Add (suite , "/Collection/find/modifiers/bool" ,
988
- test_bool_modifiers );
989
1001
TestSuite_Add (suite , "/Collection/find/modifiers/index_spec" ,
990
1002
test_index_spec_modifiers );
991
1003
TestSuite_Add (suite , "/Collection/find/comment" ,
992
1004
test_comment );
993
1005
TestSuite_Add (suite , "/Collection/find/max" ,
994
1006
test_max );
1007
+ TestSuite_Add (suite , "/Collection/find/modifiers/bool" ,
1008
+ test_snapshot );
995
1009
TestSuite_Add (suite , "/Collection/find/showdiskloc" ,
996
1010
test_diskloc );
997
1011
TestSuite_Add (suite , "/Collection/find/returnkey" ,
@@ -1002,6 +1016,8 @@ test_collection_find_install (TestSuite *suite)
1002
1016
test_batch_size );
1003
1017
TestSuite_Add (suite , "/Collection/find/limit" ,
1004
1018
test_limit );
1019
+ TestSuite_Add (suite , "/Collection/find/unrecognized" ,
1020
+ test_unrecognized_dollar_option );
1005
1021
TestSuite_Add (suite , "/Collection/find/flags" ,
1006
1022
test_query_flags );
1007
1023
0 commit comments