对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db. 集合.renameCollection()(mongosh方法)

带驱动程序的 MongoDB

This page documents a mongosh method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language:
db.collection.renameCollection(target, dropTarget)

重命名集合。为 renameCollection 数据库命令提供包装器。

Parameter
类型
说明

target

字符串

集合的新名称。将字符串括在引号中。请参阅命名限制

dropTarget

布尔

可选。如果 truemongod 在重命名集合之前删除 renameCollection 中的 target。默认值为 false

The db.collection.renameCollection() method operates within a collection by changing the metadata associated with a given collection.

有关其他警告和消息,请参阅文档 renameCollection

警告

The db.collection.renameCollection() method and renameCollection command will invalidate open cursors which interrupts queries that are currently returning data.

For MongoDB Change Streams, the db.collection.renameCollection() method and renameCollection command create an invalidate Event for any existing MongoDB Change Streams opened on the source or target collection.

在版本5.0中进行了更改。

重命名分片集群中的分片集合或非分片集合时,源集合和目标集合都以独占方式锁定在每个分片上。对源集合和目标集合的后续操作必须等待重命名操作完成。

有关 MongoDB 中锁定的更多信息,请参阅常见问题解答:并发。

renameCollection() obtains an exclusive lock on the source and target collections for the duration of the operation. All subsequent operations on the collections must wait until renameCollection() completes.

A mongodump started with --oplog fails if a client issues db.collection.renameCollection() during the dump process. See mongodump.--oplog for more information.

Call the db.collection.renameCollection() method on a collection object. For example:

db.rrecord.renameCollection("record")

该操作会将 rrecord 集合重命名为 record。如果目标名称(即 record)是现有集合的名称,则该操作会失败。

给本页内容打分

在此页面上