skip to Main Content

I am unable to connect Atlas MongoDB while using --host option, But i’m able to connect while using --uri option where did i made a mistake?

For example:

–uri option It’s working fine

mongodump --uri="mongodb+srv://<username>:<password>@<hostname>/<dbname>" --gzip --out=/dir1/dir2

–host option getting error like

Failed: error connecting to db server: no reachable servers

mongodump --host <hostname>:<port> --username <username> --password <password> --authenticationDatabase <dbusername> --gzip --db <dbname> --out /dir/dir2

2

Answers


  1. As you can see here, if you connect using --uri you use a MongoDB URI resource (starting with mongodb://)

    mongodump --uri="mongodb://mongodb0.example.com:27017" [additional options]
    

    But if you use --host you don’t, as this is not a MongoDB URI:

    mongodump --host="mongodb0.example.com:27017"  [additional options]
    

    Source: mongodump docs

    Login or Signup to reply.
  2. Based on comment you can try this:

    mongodump --uri="mongodb+srv://<username>:<password>@<hostname>/" --db=<dbname> --gzip --out=/home/dir1/
    

    You may need to specify the authentication database:

    mongodump --uri="mongodb+srv://<username>:<password>@<hostname>/?authSource=admin" --db=<dbname> --gzip --out=/home/dir1/
    

    See Authentication failure while trying to save to mongodb

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search