@@ -343,8 +343,7 @@ mongoc_collection_find (mongoc_collection_t *collection, /* IN */
343
343
* Executes a command on a cluster node matching @read_prefs. If
344
344
* @read_prefs is not provided, it will be run on the primary node.
345
345
*
346
- * This function will always return a mongoc_cursor_t with the exception
347
- * of invalid API use.
346
+ * This function will always return a mongoc_cursor_t.
348
347
*
349
348
* Parameters:
350
349
* @collection: A mongoc_collection_t.
@@ -365,28 +364,23 @@ mongoc_collection_find (mongoc_collection_t *collection, /* IN */
365
364
*/
366
365
367
366
mongoc_cursor_t *
368
- mongoc_collection_command (mongoc_collection_t * collection , /* IN */
369
- mongoc_query_flags_t flags , /* IN */
370
- bson_uint32_t skip , /* IN */
371
- bson_uint32_t n_return , /* IN */
372
- const bson_t * query , /* IN */
373
- const bson_t * fields , /* IN */
374
- const mongoc_read_prefs_t * read_prefs ) /* IN */
367
+ mongoc_collection_command (mongoc_collection_t * collection ,
368
+ mongoc_query_flags_t flags ,
369
+ bson_uint32_t skip ,
370
+ bson_uint32_t n_return ,
371
+ const bson_t * query ,
372
+ const bson_t * fields ,
373
+ const mongoc_read_prefs_t * read_prefs )
375
374
{
376
- char ns [MONGOC_NAMESPACE_MAX + 4 ];
377
-
378
- bson_return_val_if_fail (collection , NULL );
379
- bson_return_val_if_fail (query , NULL );
380
-
381
- snprintf (ns , sizeof ns , "%s.$cmd" , collection -> db );
382
- ns [sizeof ns - 1 ] = '\0' ;
375
+ BSON_ASSERT (collection );
376
+ BSON_ASSERT (query );
383
377
384
378
if (!read_prefs ) {
385
379
read_prefs = collection -> read_prefs ;
386
380
}
387
381
388
- return _mongoc_cursor_new (collection -> client , ns , flags , skip ,
389
- n_return , 0 , TRUE , query , fields , read_prefs );
382
+ return mongoc_client_command (collection -> client , collection -> db , flags ,
383
+ skip , n_return , query , fields , read_prefs );
390
384
}
391
385
392
386
@@ -417,60 +411,17 @@ mongoc_collection_command (mongoc_collection_t *collection, /* IN */
417
411
*/
418
412
419
413
bson_bool_t
420
- mongoc_collection_command_simple (
421
- mongoc_collection_t * collection , /* IN */
422
- const bson_t * command , /* IN */
423
- const mongoc_read_prefs_t * read_prefs , /* IN */
424
- bson_t * reply , /* OUT */
425
- bson_error_t * error ) /* OUT */
414
+ mongoc_collection_command_simple (mongoc_collection_t * collection ,
415
+ const bson_t * command ,
416
+ const mongoc_read_prefs_t * read_prefs ,
417
+ bson_t * reply ,
418
+ bson_error_t * error )
426
419
{
427
- mongoc_cursor_t * cursor ;
428
- const bson_t * b ;
429
- bson_bool_t ret = FALSE;
430
- bson_iter_t iter ;
431
- const char * errmsg = NULL ;
432
- int code = 0 ;
433
-
434
- bson_return_val_if_fail (collection , FALSE);
435
- bson_return_val_if_fail (command , FALSE);
420
+ BSON_ASSERT (collection );
421
+ BSON_ASSERT (command );
436
422
437
- cursor = mongoc_collection_command (collection , MONGOC_QUERY_NONE , 0 ,
438
- 1 , command , NULL , read_prefs );
439
-
440
- if (!mongoc_cursor_next (cursor , & b )) {
441
- mongoc_cursor_error (cursor , error );
442
- mongoc_cursor_destroy (cursor );
443
- if (reply ) {
444
- bson_init (reply );
445
- }
446
- return FALSE;
447
- }
448
-
449
- if (reply ) {
450
- bson_copy_to (b , reply );
451
- }
452
-
453
- if (!bson_iter_init_find (& iter , b , "ok" ) || !bson_iter_as_bool (& iter )) {
454
- if (bson_iter_init_find (& iter , b , "code" ) &&
455
- BSON_ITER_HOLDS_INT32 (& iter )) {
456
- code = bson_iter_int32 (& iter );
457
- }
458
- if (bson_iter_init_find (& iter , b , "errmsg" ) &&
459
- BSON_ITER_HOLDS_UTF8 (& iter )) {
460
- errmsg = bson_iter_utf8 (& iter , NULL );
461
- }
462
- bson_set_error (error ,
463
- MONGOC_ERROR_QUERY ,
464
- code ,
465
- "%s" , errmsg ? errmsg : "Unknown command failure" );
466
- ret = FALSE;
467
- } else {
468
- ret = TRUE;
469
- }
470
-
471
- mongoc_cursor_destroy (cursor );
472
-
473
- return ret ;
423
+ return mongoc_client_command_simple (collection -> client , collection -> db ,
424
+ command , read_prefs , reply , error );
474
425
}
475
426
476
427
0 commit comments