Report this

What is the reason for this report?

Backup only metadata using mongodump

Posted on June 19, 2025

Hi everyone,

I’m currently automating the mongodump process for both our staging and production dbs using a Python script. For this use case, I only need to export the metadata — such as collection names, indexes, and validation rules—and exclude the actual data (i.e., .bson files).

Is there a way to use mongodump (or any other tool/option) to achieve a schema-only dump without including document data?

Any help or guidance would be much appreciated!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey there 👋

As far as I know, mongodump doesn’t have a built-in flag to dump only metadata like collection names, indexes, and validation rules without the .bson data files. It always tries to include the data by default.

That said, one workaround might be to use --dumpDbUsersAndRoles and possibly combine that with empty collections (using --query '{}' --limit 0), but I’m honestly not sure if that captures indexes or validation rules reliably.

If you haven’t already, you could also look into using the listCollections and listIndexes commands directly via the Mongo shell or Python with pymongo. That might give you more precise control over what metadata you extract.

Hope that helps a bit! Would love to hear if you find a cleaner approach for this!

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.