@@ -459,29 +459,36 @@ void ShardServerProcessInterface::dropCollection(OperationContext* opCtx,
459
459
// Build and execute the _shardsvrDropCollection command against the primary shard of the given
460
460
// database.
461
461
sharding::router::DBPrimaryRouter router (opCtx->getServiceContext (), ns.dbName ());
462
- router.route (
463
- opCtx,
464
- " ShardServerProcessInterface::dropCollection" ,
465
- [&](OperationContext* opCtx, const CachedDatabaseInfo& cdb) {
466
- ShardsvrDropCollection dropCollectionCommand (ns);
467
- BSONObj cmdObj = CommandHelpers::appendMajorityWriteConcern (
468
- dropCollectionCommand.toBSON ({}), opCtx->getWriteConcern ());
469
- auto response = executeCommandAgainstDatabasePrimary (
470
- opCtx,
471
- ns.dbName (),
472
- cdb,
473
- cmdObj,
474
- ReadPreferenceSetting (ReadPreference::PrimaryOnly),
475
- Shard::RetryPolicy::kIdempotent );
476
- uassertStatusOKWithContext (response.swResponse ,
477
- str::stream () << " failed while running command " << cmdObj);
478
- auto result = response.swResponse .getValue ().data ;
479
- uassertStatusOKWithContext (getStatusFromCommandResult (result),
480
- str::stream () << " failed while running command " << cmdObj);
481
- uassertStatusOKWithContext (
482
- getWriteConcernStatusFromCommandResult (result),
483
- str::stream () << " write concern failed while running command " << cmdObj);
484
- });
462
+ try {
463
+ router.route (opCtx,
464
+ " ShardServerProcessInterface::dropCollection" ,
465
+ [&](OperationContext* opCtx, const CachedDatabaseInfo& cdb) {
466
+ ShardsvrDropCollection dropCollectionCommand (ns);
467
+ BSONObj cmdObj = CommandHelpers::appendMajorityWriteConcern (
468
+ dropCollectionCommand.toBSON ({}), opCtx->getWriteConcern ());
469
+ auto response = executeCommandAgainstDatabasePrimary (
470
+ opCtx,
471
+ ns.dbName (),
472
+ cdb,
473
+ cmdObj,
474
+ ReadPreferenceSetting (ReadPreference::PrimaryOnly),
475
+ Shard::RetryPolicy::kIdempotent );
476
+ uassertStatusOKWithContext (response.swResponse ,
477
+ str::stream () << " failed while running command "
478
+ << cmdObj);
479
+ auto result = response.swResponse .getValue ().data ;
480
+ uassertStatusOKWithContext (getStatusFromCommandResult (result),
481
+ str::stream () << " failed while running command "
482
+ << cmdObj);
483
+ uassertStatusOKWithContext (
484
+ getWriteConcernStatusFromCommandResult (result),
485
+ str::stream ()
486
+ << " write concern failed while running command " << cmdObj);
487
+ });
488
+ } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
489
+ // The database might have been dropped by a different operation, so the collection no
490
+ // longer exists.
491
+ }
485
492
}
486
493
487
494
void ShardServerProcessInterface::dropTempCollection (OperationContext* opCtx,
0 commit comments