How do I copy a database from one MongoDB server to another?

前端 未结 5 1718
逝去的感伤
逝去的感伤 2020-11-29 21:01

I have two mongodbs in different server, both start with --auth. Now I want to copy a db from one server to another.

> mongo
> use admin
&         


        
5条回答
  •  死守一世寂寞
    2020-11-29 21:42

    In addition to the answer of Mike Shauneu, if your database name on the destination server is not the same as on the source server you need to rewrite the namespace. In combination with authentication I got this to work using the --uri option, which requires a recent mongo version (>3.4.6):

    mongodump --uri="mongodb://$sourceUser:$sourcePwd@$sourceHost/$sourceDb" --gzip --archive | mongorestore --uri="mongodb://$targetUser:$targetPwd@$targetHost/$targetDb" --nsFrom="$sourceDb.*" --nsTo="$targetDb.*" --gzip --archive
    

提交回复
热议问题