Most common distinct values mongodb
问题 How to get the most common distinct values of a key in query results. Consider a collection 'collectionSample' { name : 'a', value: 10, word : 'baz' }, { name : 'a', value: 65, word : 'bar' }, { name : 'a', value: 3, word : 'foo' }, { name : 'b', value: 110, word : 'bar' }, { name : 'b', value: 256, word : 'baz' } Here I want to find the mode of key 'name', that is the most repeated distinct 'name'. The result I'm hoping to get is like {'most_common_distinct_val':a} //since a is count 3 and b