How to rename a database in MongoDB

In this article, we will see how to rename a database in MongoDB. Until MongoDB 4. or below versions, we can rename database by using db.copyDatabase(). But later versions of 4.0, it is not possible to rename a database using copyDatabase() method. The only solution is dump and restore the database.

Steps to rename a database in MongoDB:

1. Take dump of existing database. These commands has to be run from Unix level.
Continue reading How to rename a database in MongoDB

How to install MongoDB on CentOS

In this article, we will see how to install MongoDB enterprise edition on CentOS operating system.

MongoDB is open source and document oriented database. It is classified as a NoSQL database because it does not rely on a traditional table-based relational database structure. Instead, it uses JSON-like documents with dynamic schemas. Unlike relational databases, MongoDB does not require a predefined schema before you add data to a database.

We are going to perform below steps in this article:

1). Adding the MongoDB Repository
2). Installing MongoDB
3). Start and Connect to MongoDB server
4). Create a database in MongoDB server
Continue reading How to install MongoDB on CentOS

How to find current user in MongoDB

In this article, we will find out the current user that I’m logged into the MongoDB Server. We can get the current user by using the command db.runCommand().

Follow the below steps:

1) Connect to the MongoDB Server:
Syntax:

mongo hostname:27017/database -u madmin -p

mongo 127.0.01:27017/test -u madmin -p

2) Execute the below query in the Mongo Shell.
Continue reading How to find current user in MongoDB

What is capped collection in MongoDB

Definition:MongoDB Capped collection is a fixed-sized collection that automatically overwrites its oldest entries when it reaches its maximum size.

What is capped collection in MongoDB
In detailed : Capped collections have maximum size or document counts that prevent them from growing beyond maximum thresholds. All capped collections must specify a maximum size and may also specify a maximum document count. MongoDB removes older documents if a collection reaches the maximum size limit before it reaches the maximum document count.

How to create Capped collection:


Continue reading What is capped collection in MongoDB