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.
Cloning MongoDB database with MongoDB Compass
Asked Answered
There is no way. It only uses JSON/CSV files, but the conversion may break or lose some fields. More details on this post. #68851797 The only good choice is using mongodump / mongorestore. It's not hard to use it –
Milli
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
Question talks about copying databases not copying all collections. To export data mongo dump should be used. –
Meshach
Compass is not good for this usage. To use compass you need to import every collection to csv/json. But it might break/lose data, you will need to it manually for every collection, and the indexes won't be exported. –
Milli
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>
This is the right answer. There is not a good way using mongodb compass. –
Milli
© 2022 - 2024 — McMap. All rights reserved.