How to install MongoDB on Ubuntu 20.04

In this article, We will learn how to install MongoDB on Ubuntu 20.04 LTS step by step.

MongoDB is one of the most popular NoSQL databases, it is open source and freely available to download. It stores data in the form of flexible documents like JSON rather than the usual table style method found in SQL databases.

Continue reading How to install MongoDB on Ubuntu 20.04

How to get all collections from all databases in MongoDB

In this article, we will see how to get all collections from all databases in in MongoDB Server. We can get all databases and the collections in them by using db.getMongo() and db.getDBNames() methods with forEach method.

1. Run the following command from mongo shell.
Continue reading How to get all collections from all databases in MongoDB

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

How to rename collection in MongoDB

In this article, we will see the syntax to rename collection and examples to rename collections in MongoDB.

What happens when renaming collection in MongoDB?
db.collection.renameCollection() obtains an exclusive lock on the specified collections for the duration of the operation. All subsequent operations on the collections must wait until db.collection.renameCollection() releases the lock.

Syntax to rename collection in MongoDB:

db.collection.renameCollection(target, dropTarget)

Continue reading How to rename collection in MongoDB

How to stop and start MongoDB Server

In this article, we will see how to stop and start MongoDB Server on Linux and Windows Operating Systems. We have different ways to stop MongoDB server. First we will see the methods to stop MongoDB Server.

How to Stop MongoDB Server on Linux and Windows Servers:

a). How to stop MongoDB on Linux:

Continue reading How to stop and start MongoDB Server

How to change MongoDB User Password

In this article, we will describe How to change MongoDB User Password.

Syntax to change MongoDB User Password:

db.changeUserPassword(username, password)

Where
username: The name of the user whose password we wish to change.
password: The user’s new password.

Permissions required to change are current use must have built-in role “userAdmin”.

Examples to change MongoDB User Password:
Continue reading How to change MongoDB User Password

How to find MongoDB log file path

In this article, we will see How to find MongoDB log file path in Linux environment. There are different methods to find MongoDB log file path.

Method1: find MongoDB log file path using mongod.conf file:
By Default, MongoDB creates the log file at this path “/var/log/mongodb/mongodb.log”, if the log file is not found at this path, please check with the MongoDB config file.

more /etc/mongod.conf

Continue reading How to find MongoDB log file path

mongodb replication setup step by step on linux

In this article, we are going to setup MongoDB replication step by step on Ubuntu Linux.

What is Replication?
Replication is the process of synchronizing data across multiple MongoDB servers. Replication provides redundancy and increases data availability with multiple copies of data on different MongoDB servers.

mongodb replication setup step by step on linux

Continue reading mongodb replication setup step by step on linux