I need to dump database on to the folder on the server and then scp it to local machine. I tried the below methods:

mongodump --ssl -u root -p password --authenticationDatabase name -d databaseName -o /database

Failed: error connecting to db server: no reachable servers

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

Tried to switch off mongodb and copy files manually, but end up with the empty database on the local machine.

I also tried to use:

mongo --> db.copydatabase(from, to, name)

How to use mongodump? Possible to use any other way. Only through terminal, ubuntu setup doesn't have any gnu.

  • I created admin with root privileges, and using this authentication to copy database. But it still gives me auth error... I tried to show users... it gives me empty array, but if I use admin, then show users it gives me admin... Totally confused how to use mongodump. May 26, 2021 at 12:52
  • Do you mean how to copy the entire Mongo database? You can simply copy the dbPath folder (stop the database before you copy it). If you got an empty database then most likely you set dbPath wrong at your local machine. May 26, 2021 at 14:50
  • I tried to scp them, but as I remember right now, at that operation I didn't stop mongo. May be because of this my dbs on the local machine is empty? After that I started trying to mongodump... aaaaannd it's just doesn't work for me :( I have no idea why... I will try to scp tomorrow. I hope you are right. I was fighting with mongo for many many hours today... May 26, 2021 at 15:24

2 Answers 2


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.

  • Thank you for the answer. I will try it. I just saw your answer. Have a great day! May 26, 2021 at 20:46
  • I will try scp with switched off database first... Because this mongodump command I tried many variations with it, but it's fighting with me... I tried admin and plus created admin and tried with new admin with root privileges... One time I had not authenticated with admin user :)) May 26, 2021 at 20:53
  • Hello. Your answer was the closest to the right answer. Could you please fix your answer accordingly so I can give it a check mark. "My approach was too complicated to save database from the server to the vm on the local comp. As I understand the host ip could not be recognised inside of the vm, so no way this copying could be done in one step. So what I did: 1. mongodump -d (or --db?) databaseName (on the server) 2. scp database dump from the server to vm 3. mongorestore --verbose \path\from ... May 28, 2021 at 18:18
  • Obviously there is a way to mongodump from server to server, But this question would be usefull for people who get confused trying to copy database from a server to vm... May 28, 2021 at 18:20
  • I didn't actually know that this command can be used separately to dump and restore. That's why I didn't think right away to separate this command into 3 smaller steps... I have no idea who and why gave you - mark, you were very close to complete right answer... no authentication required though with the command, no ssl when copying to the same server... the commands are actually short and simple. May 28, 2021 at 18:27

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


Check similar question here

  • Hello! TY for replying. I tried this: /usr/bin/mongodump --host="webAdress.com:27017" --ssl -u root -p password --authenticationDatabase admin -d databaseName -o /database May 27, 2021 at 9:23
  • error dialing dial tcp connect: connection refused May 27, 2021 at 9:24
  • error dialing host-forDatabase:27017: dial tcp connect: connection refused May 27, 2021 at 9:24
  • When use this command with the web address: Failed: error connecting to db server: no reachable servers May 27, 2021 at 9:26
  • I know the port is right. I checked it through mongo. I tried all possible variations of connection... Still it says it cannot connect or refuse to connect. May 27, 2021 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.