Search code examples
mongodbmongodb-atlasmongodump

How to use mongodump to export specified collections only


I checked the mongodump docs, and I found this:

--collection=<collection>, -c=<collection>

Specifies a collection to backup. If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files.

This specifies one specific collection. I want to export multiple collections, but not all. Is there a way to specify all collections that I want to export?


Solution

  • You cannot specify all the collections to export, but you can specify which collections not to export using --excludeCollection, like this:

    mongodump --db=test --excludeCollection=users --excludeCollection=salaries

    It is listed on the documentation.