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