Search code examples
mongodbdatabase-backups

Using mongodump with a standard Mongo URI


The mongo client can connect with a standard URI:

mongo mongodb://<dbuser>:<dbpassword>@<server>:<port>/<db>

However, mongodump seems to require an awkward syntax breaking this up into different arguments:

mongodump -u dbuser -p dbpassword -h server -p port -d db ...

Is there a quick and easy way to pass a URI to mongodump as well?


Solution

  • The --uri option was added within a minor release of MongoDB 3.4.6. This was referenced in the JIRA issue TOOLS-1587.

    It actually did not get official documentation until the MongoDB 3.6 release, but it's now in the manual page

    --uri
    New in version 3.4.6.

    Specify a resolvable URI connection string for the mongod to which to connect.

    The following is the standard URI connection scheme:

    mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
    

    For detailed explanations of the components of this string, refer to the Connection String URI Format documentation.

    The same --uri option is added to other tools such as mongoexport, mongoimport and mongorestore.