Search code examples
mongodbscp

How to restore remote MongoDB server with local mongodump data


We have a remote MongoDB server and we have mongodump data on a local developer's machine. What is the best way to restore the remote MongoDB server data with the local data? Is there a mongo command that we can use?


Solution

  • Alright so we did this in two steps. I think you can do it in one step, with just mongorestore.

    First we moved the data from the local machine to the remote machine with the scp command:

    scp <path-to-mongofile> <remote-host>:<absolute-file-path>
    

    then we ssh'd into the remote mongod server, and used mongorestore to restore the db

    mongorestore --host=$HOST --port=$PORT -u $ADMIN_USER -p $PSWD  --db <your-db> <absolute-path-to-restore-db> --authenticationDatabase "admin"
    

    but I think the first scp command is redundant. In fact, if you cannot ssh into the server running mongod, then you will have to use the mongorestore command directly from the local developer's machine.