What is the difference between synchronous and asynchronous Replication

Following are the difference between synchronous and asynchronous Replication.

1. Asynchronous Replication: There is delay between Master and Slave(Secondary). In this data can be replicated after the transaction has been committed on the master. Which means the slave is never ahead of the master. So, in the case of writing it is usually a little behind the master. This delay also called lag.

2. Synchronous Replication: Continue reading What is the difference between synchronous and asynchronous Replication

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 copy a collection from one database to another in MongoDB

In this article, we will see how to copy a collection from one database to another in MongoDB. As a maintenance activity its routine task to copy a collection from one database to another database in MongoDB Server.

Syntax to copy a collection from one database to another in MongoDB:

db.collection_name.find().forEach(function(d){ db.getSiblingDB('target_db')['collection_in_target'].insert(d); });

Continue reading How to copy a collection from one database to another in MongoDB

How to move a collection from one database to another in MongoDB

In this article, we will see how to move a collection from one database to another in MongoDB. As a maintenance activity its routine task to move a collection from one database to another database in MongoDB Server.

Move a collection from one database to another in MongoDB Syntax:

We must run the below command in admin database only.

db.runCommand({renameCollection: 'db1.source_collection', to: 'db2.target_collection'})

Continue reading How to move a collection from one database to another in MongoDB