Backup only metadata using mongodump

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!

Hello everyone,

It’s a follow-up to my previous question. Can anyone who has experienced this suggest me some way-out ?

In general MongoDB is a schema-less database, thus your question does not make much sense.
Anyway, with a query like this, you should get all information you are looking for:

let databases = db.adminCommand({ listDatabases: 1, nameOnly: 1 }).databases.map(x => x.name)
for (let d of databases) { // don't use "db" as variable name
   db.getSiblingDB(d).getCollectionInfos()
}

Execute it and write the output to a file.