Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning MongoDB database with MongoDB Compass

Is there a way to Clone a MongoDB database and its data with MongoDB Compass to my local server? I do not want to corrupt the dev environment by accident so I want to test things out locally, but I can't find a solution for that on MongoDB Compass.

like image 631
Marius Avatar asked May 21 '26 03:05

Marius


2 Answers

MongoDB Compass has a great documentation explaining how you can import/export one collection at the time for both JSON and CSV files.

I think that there is no better answer than the link to the documentation: https://docs.mongodb.com/compass/current/import-export#import-data-into-a-collection

like image 116
Haniel Baez Avatar answered May 23 '26 18:05

Haniel Baez


To clone an existing database to a new one, use the mongodump and mongorestore commands.

To dump DB:

mongodump -d <database_name> -o <directory_backup>

To clone DB:

mongorestore -d <new_database_name> <directory_backup>/<database_name>
like image 43
C'Reality Education Avatar answered May 23 '26 16:05

C'Reality Education



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!