from typing import OrderedDict


def key_value_counts(key, collection_obj, pre_operators=(), verbose=False):
    """Counting all possible values of a given key in a collection."""
    if verbose:
        print('\nCounting values of key {} in collection {}.'.format(
            key, collection_obj.full_name))
    cur = collection_obj.aggregate(list(pre_operators) + [
        {'$group': {'_id': '$' + key, 'total': {'$sum': 1}}},
        {'$sort': {'total': -1}},
    ])
    res = {doc['_id']: doc['total'] for doc in cur}
    return OrderedDict(sorted(
        res.items(), key=lambda item: item[1], reverse=True))