Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 426
Andrew Mao Avatar asked Sep 15 '17 09:09

Andrew Mao


People also ask

What is the difference between Mongoexport and Mongodump?

mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.

What is MongoDB URI?

The URI describes the hosts to be used and options. The format of the URI is: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database.collection][?options]] mongodb:// is a required prefix to identify that this is a string in the standard connection format.


1 Answers

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.

like image 135
Neil Lunn Avatar answered Oct 14 '22 04:10

Neil Lunn