Mongoexport for Thousands of Collections


There is a database that consists of thousands of collections, and we want to export and import those collections. Is there an easy way to do this?


Mongodump as opposed to mongoexport?

Or a bit of batch file / shell script scripting, getting a list of collections and then running the export command over it.

If you need to change the restore locations you could use nsFrom and nsTo to map the names to the new locations when using mongorestore:

This will be between different MongoDB versions, so we cannot use mongodump and mongorestore.

Ahh, the other option I’ve seen was MongoSync but the limitations on that are V6 according to the docs.

Scripting this should be pretty trivial, either with a hard coded list (I love using Excel for this kind of thing) or a dynamic script to export and restore.

You could also use an ETL tool with no transforms, or if you’ve Kafka, setup some pipelines but that’s getting a little exotic.

If you just need a copy, you could stop the old server, copy all the data files to a new server, start it up and then upgrade to the desired version, but this is not feasable on a regular basis.

What versions are you going from/to?

It’s going to be from 3.x to 4.x

I guess we can do this with Notepad++
It allows selecting multiple lines, so we can copy collection names and add them to --collection=collection_name and --out=output_name.json flags that way, but that will be thousands of mongoexport commands to be run. I was just searching if there is an easier way to do this.