How to copy MongoDB database from server to local machine?

All we need is an easy explanation of the problem, so here it is.

Or just may be dump database on to the folder on the server and then scp it to local machine? I’m trying to use mongodump from /usr/bin, but nothing good comes out of it, for instance:

mongodump –ssl -u root -p password –authenticationDatabase name -d databaseName -o /database
–>Failed: error connecting to db server: no reachable servers

if:
mongodump -u root -p password –authenticationDatabase name -d databaseName -o /database
–>Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

tried to do –host=ip.ad.re.ss:27017
tried to do –host=host-name:27017
–host=127.0.0.1:27017
–host=web-address:27017

tried to switch off mongodb…

Tried to copy files manually, but end up with the empty database on the local machine…

tried to use: mongo –> db.copydatabase(from, to, name)

Nothing is happening positive… How to use mongodump? Possible to use any other way. Only through terminal, ubuntu setup doesn’t have any gnu.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

As you said – more errorless method:

  • connect to server and create dump there (like this,
    mongodump -u root -p password --authenticationDatabase admin -d databaseName -o /database)
  • scp database dump from the server to vm
  • Restore DB on VM
    mongorestore --authenticationDatabase=admin -u=root -p=password ./dump/

Based on your error:

  • you are doing something wrong in params (did you use --authenticationDatabase admin)?
  • you are doing something wrong with regarding place (server, network)

Basically, your variant should work, just need to adjust the params for sure.

Method 2

Basically what is missing from your mongodump command is… "" round your –host -value.

--host="host-name:27017"

Check similar question here

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply