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