How do I obtain the distribution of fields among a MongoDB collection, i.e the total count of documents for each field (without knowing the fields)??
E.g. considering these documents?:
{ "doc": { "a": …, "b": … } }
{ "doc": { "a": …, "c": … } }
{ "doc": { "a": …, "c": …, "d": { "e": … } } }
I would like to get
{ "a": 3, "b": 1, "c": 2, "d": 1, "d.e": 1 }
Studio3T has a "Schema" feature which does exactly that (and a bit more) for a random sample of the DB, how is the query constructed??
question from:
https://stackoverflow.com/questions/65944571/get-number-of-documents-per-field-in-mongodb-like-studio3t-schema-operation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…