翻译或纠错本页面
- Reference >
- mongo Shell Methods >
- 数据库相关方法 >
- db.getCollectionNames()
db.getCollectionNames()¶
On this page
Definition¶
Considerations¶
在 3.0.0 版更改.
For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run db.getCollectionNames() from a version of the mongo shell before 3.0 or a version of the driver prior to 3.0 compatible version, db.getCollectionNames() will return no data, even if there are existing collections. For more information, see WiredTiger and Driver Version Compatibility.
Required Access¶
The user executing the method requires either find privileges on the system.namespaces collection or the listCollections privilege action. At a minimum, the read built-in role provide the requisite permissions.
Example¶
The following returns the names of all collections in the records database:
use records
db.getCollectionNames()
The method returns the names of the collections in an array:
[ "employees", "products", "mylogs", "system.indexes" ]