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

How to clear MongoDB Shell console

We are going to see how to clear MongoDB Shell console. There are two methods to clear mongo shell on Linux and Windows operating systems.

How to clear MongoDB Shell console on Linux and Windows:

Below two methods are used to clear the mongo shell console on Linux and Windows operating systems.
Continue reading How to clear MongoDB Shell console

Step by Step MongoDB Replication setup on Windows

In this article, we will see Step by Step MongoDB Replication setup on Windows. We are going to add 1 Primary and 2 Secondary servers to replica Set.

What is replication?
Replication is a way of keeping identical copies of data on multiple servers and it is recommended for all production deployments.

Step by Step MongoDB Replication setup on Windows1
Continue reading Step by Step MongoDB Replication setup on Windows

MongoDB exception: connect failed

When tried to connect to MongoDB server, recieved the error: “MongoDB exception: connect failed”. This error occurs if MongoDB server is offline or It may be connecting with default port 27017.

MongoDB shell version v4.0.10 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb 2019-07-09T22:18:34.660-0700 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:344:17 @(connect):2:6 exception: connect failed

Reason:

Possible reason check the MongoDB server is up and running fine or not. In my case this error came because MongoDB server is down.

MongoDB exception connect failed

Solution 1:
Continue reading MongoDB exception: connect failed