Mongodb – How to copy MongoDB database from server to local machine

mongodb

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.

Best Answer

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.