- Reference >
mongo
Shell Methods >- Database Methods >
- db.getCollectionNames()
db.getCollectionNames()¶
On this page
Definition¶
-
db.
getCollectionNames
()¶ Returns an array containing the names of all collections and views in the current database, or if running with access control, the names of the collections according to user’s privilege. For details, see Required Access.
Required Access¶
The db.getCollectionNames()
is equivalent to:
- For users with the required access (privileges that grant
listCollections
action on the database), the method lists the names of all collections for the database. - For users without the required access, the method lists only the
collections for which the users has privileges. For example, if a
user has
find
on a specific collection in a database, the method would return just that collection.
Behavior¶
Client Disconnection¶
Starting in MongoDB 4.2, if the client that issued db.getCollectionNames()
disconnects before the operation completes, MongoDB marks db.getCollectionNames()
for termination using killOp
.
Example¶
The following returns the names of all collections in the records
database:
The method returns the names of the collections in an array: