@@ -506,6 +506,118 @@ test_index (void)
506
506
mongoc_client_destroy (client );
507
507
}
508
508
509
+ static void
510
+ test_index_compound (void )
511
+ {
512
+ mongoc_collection_t * collection ;
513
+ mongoc_database_t * database ;
514
+ mongoc_client_t * client ;
515
+ mongoc_index_opt_t opt ;
516
+ bson_error_t error ;
517
+ bool r ;
518
+ bson_t keys ;
519
+
520
+ mongoc_index_opt_init (& opt );
521
+
522
+ client = mongoc_client_new (gTestUri );
523
+ ASSERT (client );
524
+
525
+ database = get_test_database (client );
526
+ ASSERT (database );
527
+
528
+ collection = get_test_collection (client , "test_index_compound" );
529
+ ASSERT (collection );
530
+
531
+ bson_init (& keys );
532
+ bson_append_int32 (& keys , "hello" , -1 , 1 );
533
+ bson_append_int32 (& keys , "world" , -1 , -1 );
534
+ r = mongoc_collection_create_index (collection , & keys , & opt , & error );
535
+ ASSERT (r );
536
+
537
+ r = mongoc_collection_create_index (collection , & keys , & opt , & error );
538
+ ASSERT (r );
539
+
540
+ r = mongoc_collection_drop_index (collection , "hello_1_world_-1" , & error );
541
+ ASSERT (r );
542
+
543
+ bson_destroy (& keys );
544
+
545
+ r = mongoc_collection_drop (collection , & error );
546
+ ASSERT (r );
547
+
548
+ mongoc_collection_destroy (collection );
549
+ mongoc_database_destroy (database );
550
+ mongoc_client_destroy (client );
551
+ }
552
+
553
+ static void
554
+ test_index_geo (void )
555
+ {
556
+ mongoc_collection_t * collection ;
557
+ mongoc_database_t * database ;
558
+ mongoc_client_t * client ;
559
+ mongoc_index_opt_t opt ;
560
+ mongoc_index_opt_geo_t geo_opt ;
561
+ bson_error_t error ;
562
+ bool r ;
563
+ bson_t keys ;
564
+
565
+ mongoc_index_opt_init (& opt );
566
+ mongoc_index_opt_geo_init (& geo_opt );
567
+
568
+ client = mongoc_client_new (gTestUri );
569
+ ASSERT (client );
570
+
571
+ database = get_test_database (client );
572
+ ASSERT (database );
573
+
574
+ collection = get_test_collection (client , "test_geo_index" );
575
+ ASSERT (collection );
576
+
577
+ /* Create a basic 2d index */
578
+ bson_init (& keys );
579
+ BSON_APPEND_UTF8 (& keys , "location" , "2d" );
580
+ r = mongoc_collection_create_index (collection , & keys , & opt , & error );
581
+ ASSERT (r );
582
+
583
+ r = mongoc_collection_drop_index (collection , "location_2d" , & error );
584
+ ASSERT (r );
585
+
586
+ /* Create a 2d index with bells and whistles */
587
+ bson_init (& keys );
588
+ BSON_APPEND_UTF8 (& keys , "location" , "2d" );
589
+
590
+ geo_opt .twod_location_min = -123 ;
591
+ geo_opt .twod_location_max = +123 ;
592
+ geo_opt .twod_bits_precision = 30 ;
593
+ opt .geo_options = & geo_opt ;
594
+
595
+ r = mongoc_collection_create_index (collection , & keys , & opt , & error );
596
+ ASSERT (r );
597
+
598
+ r = mongoc_collection_drop_index (collection , "location_2d" , & error );
599
+ ASSERT (r );
600
+
601
+ /* Create a Haystack index */
602
+ bson_init (& keys );
603
+ BSON_APPEND_UTF8 (& keys , "location" , "geoHaystack" );
604
+ BSON_APPEND_INT32 (& keys , "category" , 1 );
605
+
606
+ mongoc_index_opt_geo_init (& geo_opt );
607
+ geo_opt .haystack_bucket_size = 5 ;
608
+ opt .geo_options = & geo_opt ;
609
+
610
+ r = mongoc_collection_create_index (collection , & keys , & opt , & error );
611
+ ASSERT (r );
612
+
613
+ r = mongoc_collection_drop_index (collection , "location_geoHaystack_category_1" , & error );
614
+ ASSERT (r );
615
+
616
+ mongoc_collection_destroy (collection );
617
+ mongoc_database_destroy (database );
618
+ mongoc_client_destroy (client );
619
+ }
620
+
509
621
510
622
static void
511
623
test_count (void )
@@ -1216,6 +1328,8 @@ test_collection_install (TestSuite *suite)
1216
1328
TestSuite_Add (suite , "/Collection/insert" , test_insert );
1217
1329
TestSuite_Add (suite , "/Collection/save" , test_save );
1218
1330
TestSuite_Add (suite , "/Collection/index" , test_index );
1331
+ TestSuite_Add (suite , "/Collection/index_compound" , test_index_compound );
1332
+ TestSuite_Add (suite , "/Collection/index_geo" , test_index_geo );
1219
1333
TestSuite_Add (suite , "/Collection/regex" , test_regex );
1220
1334
TestSuite_Add (suite , "/Collection/update" , test_update );
1221
1335
TestSuite_Add (suite , "/Collection/remove" , test_remove );
0 commit comments