Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (47.6k points)

Is there a simple way to do this?

1 Answer

0 votes
by (106k points)
To copy a collection from one database to another in MongoDB there is no command in MongoDB that would do this but you can do something like as follows:-

db.<collection_name>.find().forEach(function(d){ db.getSiblingDB('<new_database>')

['<collection_name>'].insert(d); 

});

Other than this, you can do a mongodump of a collection from one database and then mongorestore the collection to the other database.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...