db.getCollectionNames()

在本页面

Definition

Considerations

在 3.0.0 版中更改。

对于使用WiredTiger存储引擎的 MongoDB 3.0 部署,如果您从 3.0 之前的mongo shell 版本或3 .0 兼容版本之前的驱动程序版本运行db.getCollectionNames(),即使有现有集合,db.getCollectionNames()也不会返回任何数据。有关更多信息,请参见WiredTiger 和驱动程序版本兼容性

Required Access

执行该方法的用户需要system.namespaces集合具有find特权或listCollections特权操作。 read built-in role至少提供必要的权限。

Example

以下内容返回records数据库中所有集合的名称:

use records
db.getCollectionNames()

该方法在数组中返回集合的名称:

[ "employees", "products", "mylogs", "system.indexes" ]
首页