export multiple collection using mongoexport

3.5k views Asked by At

Iam creating a test environment on the same ubuntu server where my prod enviroment is hosted.

So i need to create a replica of the mongodb database iam using on the ubuntu server but add '_test' to the end of the name of the database. That is the reason i dont want to use mongodump.

  1. what would happend if i export the prod db version and restore it on the same server with the same db name. Would it just override?

  2. So to solve the problem i wanna export all the collection at ones and import all the collection at ones. Is it possible? If yes. How is this done? If no... does this mean i have to do an export/import command for every collection? This is do able for because i only have like 10 collections. Or is there a better way to solve my problem?

  3. What does the mongodbexport.exe do? it came with the mongo db tools in the bin folder? when i execute it there seems like a metrics.interim was created. What is that?

1

There are 1 answers

0
AlexisG On

You can only use mongoimport and mongoexport on only one collection at a time.

You could use some bash script to simplify the task

Something like this :

database = ""
host = ""
coll = ""
username = ""
password = ""
for VARIABLE in "collection_1" "collection_2"
do
    echo VARIABLE
    mongoexport --db $database --collection $coll --host $host --username $username --password $password --out $collection.json
done