Is there a way to quickly check every table in a mongodb database with the column "title"?

Viewed 15

Is there a way to quickly check every table in a mongodb database with the column "title"? I need to identify every table or rather collection where there's a column with the word "title", is there a way to do this using a mongodb query?

1 Answers

In Mongo there is no straight forward query to check all collections and fields. Instead, you can get a list of all collections using getCollectionInfos and then query each collection to see if there exists the field that you are looking for.

db.getCollectionInfos().forEach(function(c){
    
    result = db.getCollection(c.name).findOne({"title":{$exists:true}});
    
    if(result != null){
        print(c.name);
    }
}
);

This will not look for nested documents, though.

Related