发布于 2015-09-14 14:59:55 | 265 次阅读 | 评论: 0 | 来源: 网络整理
The renameCollection command is an administrative command that changes the name of an existing collection. You specify collections to renameCollection in the form of a complete namespace, which includes the database name. To rename a collection, issue the renameCollection command against the admin database in the form:
{ renameCollection: <source-namespace>, to: <target-namespace>[, dropTarget: <boolean> ] }
The dropTarget argument is optional.
If you specify a collection to the to argument in a different database, the renameCollection command will copy the collection to the new database and then drop the source collection.
参数: |
|
---|---|
Exception: |
|
You can use renameCollection in production environments; however:
警告
renameCollection will fail if target is the name of an existing collection and you do not specify dropTarget: true.
If the renameCollection operation does not complete the target collection and indexes will not be usable and will require manual intervention to clean up.
The shell helper db.collection.renameCollection() provides a simpler interface to using this command within a database. The following is equivalent to the previous example:
db.source-namespace.renameCollection( "target" )
警告
You cannot use renameCollection with sharded collections.
警告
This command obtains a global write lock and will block other operations until it has completed.