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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.