'Returns a filter which will accept results if and only if
they are accepted by both cond1 and cond2.'

@staticmethod
def _flt_and(cond1, cond2):

    cond1k = set(cond1)
    cond2k = set(cond2)
    cond = {}
    if ('$and' in cond1):
        cond1k.remove('$and')
        cond['$and'] = cond1['$and']
    if ('$and' in cond2):
        cond2k.remove('$and')
        cond['$and'] = (cond.get('$and', []) + cond2['$and'])
    for k in cond1k.difference(cond2k):
        cond[k] = cond1[k]
    for k in cond2k.difference(cond1k):
        cond[k] = cond2[k]
    for k in cond1k.intersection(cond2k):
        if (cond1[k] == cond2[k]):
            cond[k] = cond1[k]
        else:
            cond['$and'] = (cond.get('$and', []) + [{k: cond1[k]}, {k: cond2[k]}])
    return cond
