def obtain_collection_keys(collection, filter={}):
    """
    Function used to obtain all the keys of entries in a MongoDb collection

    :param collection: a mongodb collection
    :param filter: a filter for mongodb find function
    :return: a dictionary containing all the keys of all the entries obtained by the find function,
        with the number of ocurrences of the key in the value
    """
    keys = {}
    for entry in collection.find(filter):
        for key in entry:
            keys[key] = keys.setdefault(key, 0) + 1
    return keys