Using mongodump with a standard Mongo URI

Easy steps to getting dump and restore whole database at once with any data loses

take dump in the local machine

mongodump --uri "mongodb+srv://username:[email protected]/dbname" --out "C:\databaseDump"

**locate to the dumped folder and restore to local database **

mongorestore --db dbname C:\databaseDump\dbname

restore to remote database

mongorestore --uri "mongodb+srv://username:[email protected]/dbname" --db dbname C:\databaseDump\dbname

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.


Answer: 05-15-2020

I know this is a late answer, but it solved my problem.
To dump using an URI, do:

mongodump --uri=[uri]/[db]

where:

  • uri is your URI (e.g. mongodb+srv://john:[email protected])
  • db is the database that you want to dump (e.g. sales)

So in this artificial example, it would be like this:

mongodump --uri=mongodb+srv://john:[email protected]/sales

So if this really did not work, edit the file /etc/resolv.conf and change nameserver value to e.g. 8.8.8.8, like this:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

# nameserver 127.0.0.53
nameserver 8.8.8.8
options edns0

Now it should works.