diff options
Diffstat (limited to 'src/mongo/db/commands/count_cmd.cpp')
-rw-r--r-- | src/mongo/db/commands/count_cmd.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index 2f9a844950b..b2e23e4887c 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -181,10 +181,15 @@ public: // Prevent chunks from being cleaned up during yields - this allows us to only check the // version on initial entry into count. - auto rangePreserver = - CollectionShardingState::get(opCtx, nss) - ->getOwnershipFilter( - opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup); + auto* const css = CollectionShardingState::get(opCtx, nss); + boost::optional<ScopedCollectionFilter> rangePreserver; + if (css->getCollectionDescription(opCtx).isSharded()) { + rangePreserver.emplace( + CollectionShardingState::get(opCtx, nss) + ->getOwnershipFilter( + opCtx, + CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup)); + } auto expCtx = makeExpressionContextForGetExecutor( opCtx, request.getCollation().value_or(BSONObj()), nss); @@ -244,10 +249,15 @@ public: // Prevent chunks from being cleaned up during yields - this allows us to only check the // version on initial entry into count. - auto rangePreserver = - CollectionShardingState::get(opCtx, nss) - ->getOwnershipFilter( - opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup); + auto* const css = CollectionShardingState::get(opCtx, nss); + boost::optional<ScopedCollectionFilter> rangePreserver; + if (css->getCollectionDescription(opCtx).isSharded()) { + rangePreserver.emplace( + CollectionShardingState::get(opCtx, nss) + ->getOwnershipFilter( + opCtx, + CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup)); + } auto statusWithPlanExecutor = getExecutorCount(makeExpressionContextForGetExecutor( |