mongodb 怎么合并多个 database

新手上路,请多包涵

现在一个实例里有 DBA, DBB, DBC, NewDB,如何把ABC导入到NewDB?
结构是一样的,试过For InsertInsertMany,但是数据有接近500W,插了没几条就不工作了。而且效率太低。
请问有什么高效的办法吗?

阅读 5.6k
1 个回答

如果是复制集的话倒是有办法,不是十分直观不过我们有renameCollection Command:
注意:务必读完上面的链接再动手。

{ 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" } )
...
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进