24
votes

For some reason I cant connect to atlas using the connection string but instead of using mongo use mongodump. I have tried all type of string.

So its either I get "positional argument not allowed" when the I just replace mongo with mongodump or I get

"failed: error connecting to db: no reachable servers" when I change the host from "mongo://replset1:27017,replset2:27017,replset3:271017/test?replicaSet=replicaSetName" to --host replicaSetName/replset1:27017,replset:27017,replset3:27017

Anyone know what the problem is here.

Rememeber I can make connections using mongo client.

10
The Atlas dashboard where you see an overview of your clusters has three buttons Metric|Connect|... click ... and select command line tools, under Binary Import and Export tools there'll be a mongorestore and mongodb commands you need. Tweak to reference your local /bin folder and passwords. - Anthony

10 Answers

54
votes

Currently mongoDB Atlas has a copy and paste option for "mongodump" in the "Command Line Tools" section of your cluster. First login to your mongoDB Atlas cluster. Next, on the left side of the screen make sure "Clusters" is chosen. Then, you'll see two options "Overview" and "Security", make sure "Overview" is chosen. Directly below "Overview" you should see "Sandbox". Under "Sandbox" you should see the name of your cluster which is a clickable link, click it. You'll then see a number of optional links to click, click "Command Line Tools". Here you'll see the copy and paste option for "mongodump".

13
votes

In my case I finally got it this way:

# mongodump -d DB-NAME -u SUPERUSER -p "SUPERUSER-PASSWORD" -o "PATH/TO/DUMP/FOLDER" --authenticationDatabase AUTH-DB --ssl --port 27017 -h "REPLICA-SET-NAME/CLUSTER-SHARD-00-00,CLUSTER-SHARD-00-01,CLUSTER-SHARD-00-02"

Where:

  • DB-NAME: Name of the database to backup
  • SUPERUSER: User name with all privileges, the one you got creating the cluster
  • SUPERUSER-PASSWORD: Self explanatory ;)
  • PATH/TO/DUMP/FOLDER: Where you want to save the dump
  • AUTH-DB: The database for authentication, by default is called "admin"
  • REPLICA-SET-NAME: The name of the replica set in the form "cluster-name-shard-0"
  • CLUSTER-SHARD: Name of the cluster shards IE: "cluster-name-shard-00-00-kb2rd.mongodb.net, cluster-name-shard-00-01-kb2rd.mongodb.net, cluster-name-shard-00-02-kb2rd.mongodb.net"
11
votes

If you have the srv string.
You can simply do mongodump --uri=mongodb+srv://xxx:[email protected].
This seemed to just straight up work for me :)

4
votes

Every time when I dump my database from mongo atlas I use this command. Hope this helps. Happy coding... :)

mongodump -d $dbName -u $username -p $password \
-o . --authenticationDatabase admin --ssl --port 27017 \
-h $hostname
4
votes

As @charliecode mentioned, MongoDB Atlas actually shows you a proper way how to use mongodump/mongorestore/mongoexport/mongoimport. Visit your cluster in Atlas GUI, open Command Line Tools (hidden under more options), scroll down until you will see:

mongodump --uri mongodb+srv://<username>:<PASSWORD>@made-up-url.5a45j.mongodb.net/<DATABASE>

However I recommend a little change. Omit <password> in the URI because there is a good chance your password contains some special characters and it's both annoying and insecure to use non-encoded passwords directly in commands. mongodump will prompt you for the password afterwards.

mongodump --uri mongodb+srv://<username>@made-up-url.5a45j.mongodb.net/<DATABASE>

Painless.

2
votes

As of Feb 2021 with mongoDB v4.4; You can use

mongodump --uri mongodb+srv://<USERNAME>:<PASSWORD>@cluster-name.mongodb.net/<DATABASE> 

N.B: If it does not work, try to omitting the database name.

1
votes

I'm getting the same error, but the following workaround has worked for me. It seems you can connect to a recent snapshot of your DB via Backup Tunnel. Basically what it does is it allows emulates MongoDB Server on a specified port. This implies you can make regular connection to it such as with 'mongodump'.

Link to official docs - https://docs.atlas.mongodb.com/restore-queryable-backup/

0
votes

mongodump --host hostname --username username --password password --db databasename --out folderlocation

0
votes

mongodump --uri "your_atlas_connection_string"

Atlas connection string contains your user name, password, and database name. You can choose your --out directory.

   Anil-iMac:bin anil$ ./mongodump --uri "mongodb+srv://USER_NAME:[email protected]/YOUR_DB_NAME?authSource=admin&replicaSet=atlas-m2x7xg-shard-0&readPreference=primary&appname=MongoDB%20Compass%20Community&ssl=true" --out /Users/anil/Development/Personal/mongodb-database-tools-macos-x86_64-100.1.1/bin/bkup 
0
votes

First of all, make sure Network access to Atlas cluster is proper. For taking a remote dump, add your instances IP to Atlas Ip access list.

sudo mongodump --uri mongodb+srv://admin:Anson_Alexander%[email protected]/<NAME_OF_REQUIRED_DB>?authSource=admin&replicaSet=atlas-rz#80g0-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true --out <LOCATION>