@@ -82,6 +82,34 @@ main (int argc, char *argv[])
82
82
mongoc_database_destroy (db );
83
83
}
84
84
85
+ // Check that $listSearchIndexes pipeline stage is supported.
86
+ // This is intended to check that a MongoDB Atlas cluster is used.
87
+ {
88
+ const char * pipeline_str =
89
+ BSON_STR ({"pipeline" : [ {"$listSearchIndexes" : {}} ]});
90
+ bson_t pipeline ;
91
+ ASSERT (bson_init_from_json (& pipeline , pipeline_str , -1 , & error ));
92
+ mongoc_cursor_t * cursor =
93
+ mongoc_collection_aggregate (coll ,
94
+ MONGOC_QUERY_NONE ,
95
+ & pipeline ,
96
+ NULL /* opts */ ,
97
+ NULL /* read_prefs */ );
98
+ const bson_t * got ;
99
+ while (mongoc_cursor_next (cursor , & got ))
100
+ ;
101
+ if (mongoc_cursor_error (cursor , & error )) {
102
+ bson_destroy (& pipeline );
103
+ mongoc_cursor_destroy (cursor );
104
+ HANDLE_ERROR ("Failed to run $listSearchIndexes with error: %s\n"
105
+ "Does the URI point to a MongoDB Atlas cluster? %s" ,
106
+ error .message ,
107
+ uri_string );
108
+ }
109
+ bson_destroy (& pipeline );
110
+ mongoc_cursor_destroy (cursor );
111
+ }
112
+
85
113
{
86
114
// Create an Atlas Search Index ... begin
87
115
bson_t cmd ;
@@ -102,10 +130,7 @@ main (int argc, char *argv[])
102
130
if (!mongoc_collection_command_simple (
103
131
coll , & cmd , NULL /* read_prefs */ , NULL /* reply */ , & error )) {
104
132
bson_destroy (& cmd );
105
- HANDLE_ERROR ("Failed to run createSearchIndexes: %s.\n"
106
- "The URI '%s' must refer to a MongoDB Atlas cluster." ,
107
- error .message ,
108
- uri_string );
133
+ HANDLE_ERROR ("Failed to run createSearchIndexes: %s" , error .message );
109
134
}
110
135
printf ("Created index: \"test-index\"\n" );
111
136
bson_destroy (& cmd );
0 commit comments