Now there are DBA, DBB, DBC, and NewDB in an instance. How to import ABC into NewDB?
The structure is the same. I tried For Insert
and InsertMany
, but the data is close to 500W, and it won’t work after inserting a few items. And the efficiency is too low.
Is there any efficient way?
PHP中文网2017-06-21 10:13:34
If it is a copy set, there is a way. It is not very intuitive, but we have renameCollection Command:
Note: Be sure to read the above link before doing it.
{ renameCollection: "<source_namespace>", to: "<target_namespace>", dropTarget: <true|false> }
Field | Type | Description |
---|---|---|
renameCollection | string | 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" } )
...