'Filters records with open port number between minn and maxn'

@staticmethod
def searchcountopenports(minn=None, maxn=None, neg=False):

    assert ((minn is not None) or (maxn is not None))
    flt = []
    if (minn == maxn):
        return {'openports.count': ({'$ne': minn} if neg else minn)}
    if (minn is not None):
        flt.append({('$lt' if neg else '$gte'): minn})
    if (maxn is not None):
        flt.append({('$gt' if neg else '$lte'): maxn})
    if (len(flt) == 1):
        return {'openports.count': flt[0]}
    if neg:
        return {'$or': [{'openports.count': cond} for cond in flt]}
    return {'openports.count': {'$lte': maxn, '$gte': minn}}
