How to Backup and Restore MongoDB database

In this article, we will see the steps to Backup and Restore MongoDB database. It is important to take regular backups of our system. Backups are good protection against most types of failures.

mongodump tool is used to take backup of MongoDB database or collection or subset of collection.
mongorestore tool is used to restore database or collection on the target database.

mongodump Syntax:

mongodump [options]

Few options are:

–authenticationDatabase
–db
–username
–password
–out
–host
–uri
–collection
–query
–archive
–oplog
–dumpDbUsersAndRoles
–excludeCollection

MongoDB backup examples:

Continue reading How to Backup and Restore MongoDB database

MongoDB error connecting to host: could not connect to server: server selection error: server selection timeout

In this article, we will see to troubleshoot the problem for connectivity between different MongoDB servers. I got below error when tried to restore database from local to remote host.

2019-11-20T15:56:59.536-0800 error connecting to host: could not connect to server: server selection error: server selection timeout current topology: Type: Single Servers: Addr: 192.168.152.141:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(192.168.152.141:27017[-121]) connection is closed

Continue reading MongoDB error connecting to host: could not connect to server: server selection error: server selection timeout