On this page
db.collection.renameCollection()
在本页面
Definition
db.collection.
renameCollection
(* target , dropTarget *)- 重命名集合。提供renameCollection database command的包装。
Parameter | Type | Description |
---|---|---|
target |
string | 集合的新名称。将字符串用引号引起来。参见Naming Restrictions。 |
dropTarget |
boolean | 可选的。如果为true ,则mongod在重命名集合之前会删除renameCollection的目标。默认值为false 。 |
Behavior
db.collection.renameCollection()方法通过更改与给定集合关联的元数据在集合内运行。
有关其他警告和消息,请参阅文档renameCollection。
Warning
db.collection.renameCollection()方法和renameCollection命令将使打开的游标无效,该游标会中断当前正在返回数据的查询。
该方法具有以下局限性:
db.collection.renameCollection()无法在数据库之间移动集合。将renameCollection用于这些重命名操作。
分片集合不支持db.collection.renameCollection()。
您不能重命名views。
Example
在集合对象上调用db.collection.renameCollection()方法。例如:
db.rrecord.renameCollection("record")
此操作会将rrecord
集合重命名为record
。如果目标名称(即record
)是现有集合的名称,则该操作将失败。