On this page本页内容
db.collection.
renameCollection
(target, dropTarget)¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
Renames a collection. 重命名集合。Provides a wrapper for the 为renameCollection
database command.renameCollection
数据库命令提供包装。
target |
string | |
dropTarget |
boolean | true , mongod drops the target of renameCollection prior to renaming the collection. true ,mongod 会在重命名集合之前删除renameCollection 的trget 。false .false 。 |
The db.collection.renameCollection()
method operates within a collection by changing the metadata associated with a given collection.db.collection.renameCollection()
方法通过更改与给定集合关联的元数据在集合中运行。
Refer to the documentation 有关其他警告和消息,请参阅renameCollection
for additional warnings and messages.renameCollection
文档。
Warning
The db.collection.renameCollection()
method and renameCollection
command will invalidate open cursors which interrupts queries that are currently returning data.db.collection.renameCollection()
方法和renameCollection
命令将使中断当前返回数据的查询的打开游标无效。
For Change Streams, the 对于更改流,db.collection.renameCollection()
method and renameCollection
command create an invalidate Event for any existing Change Streams opened on the source or target collection.db.collection.renameCollection()
方法和renameCollection
命令会为在源集合或目标集合上打开的任何现有更改流创建一个invalidate
事件。
db.collection.renameCollection()
renameCollection
for these rename operations.renameCollection
。db.collection.renameCollection()
Changed in version 4.2.在版本4.2中更改。
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. renameCollection()
完成。Prior to MongoDB 4.2, renaming a collection within the same database with 在MongoDB 4.2之前,使用renameCollection
required obtaining an exclusive database lock.renameCollection
重命名同一数据库中的集合需要获得独占数据库锁。
mongodump
mongodump
的互动¶A 如果客户端在转储过程中发出mongodump
started with --oplog
fails if a client issues db.collection.renameCollection()
during the dump process. db.collection.renameCollection()
,则以--oplog
启动的mongodump
将失败。See 请参阅mongodump.--oplog
for more information.mongodump.--oplog
以获取更多信息。
Call the 对集合对象调用db.collection.renameCollection()
method on a collection object. db.collection.renameCollection()
方法。For example:例如:
This operation will rename the 此操作将rrecord
collection to record
. rrecord
集合重命名为record
。If the target name (i.e. 如果目标名称(即record
) is the name of an existing collection, then the operation will fail.record
)是现有集合的名称,则操作将失败。