summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/list_collections.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands/list_collections.cpp')
-rw-r--r--src/mongo/db/commands/list_collections.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 8d711c43cf2..e1f20746eb4 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/catalog/collection_catalog_entry.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/index_catalog.h"
+#include "mongo/db/catalog/uuid_catalog_helper.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/list_collections_filter.h"
@@ -186,7 +187,6 @@ BSONObj buildCollectionBson(OperationContext* opCtx,
return b.obj();
}
- Lock::CollectionLock clk(opCtx, nss, MODE_IS);
CollectionOptions options = collection->getCatalogEntry()->getCollectionOptions(opCtx);
// While the UUID is stored as a collection option, from the user's perspective it is an
@@ -311,6 +311,7 @@ public:
continue;
}
+ Lock::CollectionLock clk(opCtx, nss, MODE_IS);
Collection* collection = db->getCollection(opCtx, nss);
BSONObj collBson =
buildCollectionBson(opCtx, collection, includePendingDrops, nameOnly);
@@ -320,25 +321,25 @@ public:
}
}
} else {
- for (auto collIt = db->begin(opCtx); collIt != db->end(opCtx); ++collIt) {
- auto collection = *collIt;
- if (!collection) {
- break;
- }
-
- if (authorizedCollections &&
- (collection->ns().coll().startsWith("system.") ||
- !as->isAuthorizedForAnyActionOnResource(
- ResourcePattern::forExactNamespace(collection->ns())))) {
- continue;
- }
- BSONObj collBson =
- buildCollectionBson(opCtx, collection, includePendingDrops, nameOnly);
- if (!collBson.isEmpty()) {
- _addWorkingSetMember(
- opCtx, collBson, matcher.get(), ws.get(), root.get());
- }
- }
+ mongo::catalog::forEachCollectionFromDb(
+ opCtx,
+ dbname,
+ MODE_IS,
+ [&](Collection* collection, CollectionCatalogEntry* catalogEntry) {
+ if (authorizedCollections &&
+ (collection->ns().coll().startsWith("system.") ||
+ !as->isAuthorizedForAnyActionOnResource(
+ ResourcePattern::forExactNamespace(collection->ns())))) {
+ return true;
+ }
+ BSONObj collBson = buildCollectionBson(
+ opCtx, collection, includePendingDrops, nameOnly);
+ if (!collBson.isEmpty()) {
+ _addWorkingSetMember(
+ opCtx, collBson, matcher.get(), ws.get(), root.get());
+ }
+ return true;
+ });
}
// Skipping views is only necessary for internal cloning operations.