@@ -224,19 +224,28 @@ mongoc_collection_aggregate (mongoc_collection_t *collection, /* IN */
224
224
const bson_t * options , /* IN */
225
225
const mongoc_read_prefs_t * read_prefs ) /* IN */
226
226
{
227
+ mongoc_server_description_t * selected_server ;
228
+ bson_error_t error ;
227
229
mongoc_cursor_t * cursor ;
228
230
bson_iter_t iter ;
229
231
bson_t command ;
230
232
bson_t child ;
231
233
int32_t batch_size = 0 ;
232
- bool try_cursor = true ;
234
+ bool use_cursor ;
233
235
234
236
bson_return_val_if_fail (collection , NULL );
235
237
bson_return_val_if_fail (pipeline , NULL );
236
238
239
+ selected_server = mongoc_topology_select (collection -> client -> topology ,
240
+ MONGOC_SS_READ ,
241
+ read_prefs ,
242
+ 15 ,
243
+ & error );
244
+
245
+ use_cursor = selected_server -> max_wire_version >= 1 ;
246
+
237
247
bson_init (& command );
238
248
239
- TOP :
240
249
BSON_APPEND_UTF8 (& command , "aggregate" , collection -> collection );
241
250
242
251
/*
@@ -251,7 +260,7 @@ mongoc_collection_aggregate (mongoc_collection_t *collection, /* IN */
251
260
}
252
261
253
262
/* for newer version, we include a cursor subdocument */
254
- if (try_cursor ) {
263
+ if (use_cursor ) {
255
264
bson_append_document_begin (& command , "cursor" , 6 , & child );
256
265
257
266
if (options && bson_iter_init (& iter , options )) {
@@ -280,18 +289,16 @@ mongoc_collection_aggregate (mongoc_collection_t *collection, /* IN */
280
289
cursor = mongoc_collection_command (collection , flags , 0 , 0 , batch_size ,
281
290
& command , NULL , read_prefs );
282
291
283
- if (try_cursor ) {
292
+ cursor -> hint = selected_server -> id ;
293
+
294
+ if (use_cursor ) {
284
295
/* even for newer versions, we get back a cursor document, that we have
285
296
* to patch in */
286
-
287
297
_mongoc_cursor_cursorid_init (cursor );
288
298
cursor -> limit = 0 ;
289
299
290
300
if (! _mongoc_cursor_cursorid_prime (cursor )) {
291
301
mongoc_cursor_destroy (cursor );
292
- bson_reinit (& command );
293
- try_cursor = false;
294
- goto TOP ;
295
302
}
296
303
} else {
297
304
/* for older versions we get an array that we can create a synthetic
0 commit comments