mongo数据导入导出

第一步:先登陆mongo,172.16.103.213
 mongo -usa  -p --authenticationDatabase admin 
密码:******

第二步:进入mongo命令行
 输入:mongo
  show dbs
  use 数据库名
 删除数据库  db.dropDatabase();


第三部:导入数据库
db.copyDatabase("newdatabasename","copydatabasename","ip:port","username","password","MONGODB-CR")

 eg. 
db.copyDatabase("YmtBuyerProduct","YmtBuyerProduct","172.16.101.169:27017","BuyerProductuser","123456","MONGODB-CR")

db.copyDatabase("MQ_Configuration_201609","MQ_Configuration_201609","172.16.101.169:27017","mqdatauser","123456","MONGODB-CR")



 问题1. "errmsg" : "exception: nextSafe(): { $err: "not master and slaveOk=false", code: 13435 }"
 

 rs.slaveOk()
从库通过shell连进去默认是不可读的 

问题2:如果有进程正在写,会创建库,就会导致导入失败
 
如果关不掉相应进程,需要多次删除跟导入,在其他进程写入库前导入 
原文地址:https://www.cnblogs.com/chenjiazhu/p/7425024.html