The namespace of the collection to rename. The namespace is a combination of the database name and the name of the collection.
to
string
The new namespace of the collection. If the new namespace specifies a different database, the renameCollection command copies the collection to the new database and drops the source collection.
dropTarget
boolean
Optional. If true, mongod will drop the target of renameCollection prior to renaming the collection. The default value is false.
Example:
use admin db.runCommand( { renameCollection: "DBA.xxx", to: "NewDB.xxx" } ) db.runCommand( { renameCollection: "DBA.yyy", to: "NewDB.yyy" } ) ...
如果是複製集的話倒是有辦法,不是十分直觀不過我們有renameCollection Command:
注意:務必讀完上面的連結再動手。
Example: