Dump MongoDB Atlas DB with mongodump

MongoDB Atlas documentation recommends using the following mongodump command with URI syntax to dump a database. But it does not work well with as reported at https://github.com/golang/go/issues/37362

$ mongodump --uri="mongodb+srv://dbUser:mypass@mycluster.jnszz.mongodb.net/mymongodb"2021-03-03T19:15:19.165+0000 error parsing command line options: error parsing uri: lookup mycluster.jnszz.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message2021-03-03T19:15:19.165+0000 try 'mongodump --help' for more information

For that reason, I use syntax. It requires a replica set name. To learn replica set name you can connect to db using with the following SRV format.

$ mongo "mongodb+srv://dbUser:mypass@mycluster.jnszz.mongodb.net/admin?retryWrites=true&w=majority"
MongoDB shell version v4.2.12
connecting to: mongodb://mycluster-shard-00-01.jnszz.mongodb.net:27017,mycluster-shard-00-00.jnszz.mongodb.net:27017,mycluster-shard-00-02.jnszz.mongodb.net:27017/admin?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=atlas-uonl2a-shard-0&retryWrites=true&ssl=true&w=majority
2021-03-03T19:08:05.064+0000 I NETWORK [js] Starting new replica set monitor for atlas-uonl2a-shard-0/mycluster-shard-00-01.jnszz.mongodb.net:27017,mycluster-shard-00-00.jnszz.mongodb.net:27017,mycluster-shard-00-02.jnszz.mongodb.net:27017
2021-03-03T19:08:05.064+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to mycluster-shard-00-02.jnszz.mongodb.net:27017
2021-03-03T19:08:05.064+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to mycluster-shard-00-00.jnszz.mongodb.net:27017
2021-03-03T19:08:05.064+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to mycluster-shard-00-01.jnszz.mongodb.net:27017
2021-03-03T19:08:05.164+0000 I NETWORK [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for atlas-uonl2a-shard-0 is atlas-uonl2a-shard-0/mycluster-shard-00-00.jnszz.mongodb.net:27017,mycluster-shard-00-01.jnszz.mongodb.net:27017,mycluster-shard-00-02.jnszz.mongodb.net:27017
MongoDB server version: 4.4.4
WARNING: shell and server versions do not match
MongoDB Enterprise atlas-uonl2a-shard-0:PRIMARY>

in above output, our replica set name is

and our replica members;

mycluster-shard-00-00.jnszz.mongodb.net:27017
mycluster-shard-00-01.jnszz.mongodb.net:27017
mycluster-shard-00-02.jnszz.mongodb.net:27017

then we can use the following command to dump DB.

$ mongodump --host  atlas-uonl2a-shard-0/mycluster-shard-00-00.jnszz.mongodb.net:27017,mycluster-shard-00-01.jnszz.mongodb.net:27017,mycluster-shard-00-02.jnszz.mongodb.net:27017 \
--ssl --username dbUser --password mypass \
--authenticationDatabase admin --db mydb --out dump-mydb

MYtEte7qHn96 --authenticationDatabase admin --db mydb --out dump-mydb
2021-03-03T19:21:53.869+0000 WARNING: ignoring unsupported URI parameter 'replicaset'
2021-03-03T19:21:53.973+0000 writing mydb.role to dump-mydb/mydb/role.bson
2021-03-03T19:21:53.974+0000 done dumping mydb.role (4 documents)
...
2021-03-03T19:21:54.071+0000 done dumping mydb.applicationMetadata (1 document)

Note: You can also get replica set name in MongoDB Atlas admin portal at https://cloud.mongodb.com/

Click icon under your cluster name, then click to then select Driver and

Ismail YENIGUL

Devops Engineer

Devops Engineer