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?
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With