Skip to content

MongoDB: Copy a collection from one database to another

It’s quite simple

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

You can do a mongodump of a collection from one database and then mongorestore the collection to the other database.

I used robomongo and it a documents view, just used this query with the right names for collections and databases, I was able to copy around 3000 records in less than a second on my old Macbook air.

Leave a Reply

Your email address will not be published. Required fields are marked *