mongodb实现两个表之间的数据转移


  1. 同一个Mongodb实例下:
切换到源库
use db_source; # db_source = 需要拷贝数据的库
var test_copy = db_source.table.find(); # table = 要迁移的表
use db_target; # db_target = 拷贝的目标库
test_copy.forEach(function(d){db.coll_target.insert(d)}); # coll_target = 目标表

不同Mongodb实例之间
可以使用mongodump和mongorestore

备份:
mongodump -h host:port -d db_source -c collection_source
恢复
mongorestore -h host:port -d db_target -c collection_target dump/collection_source.bson


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM