'Look for a CPE by type (a, o or h), vendor, product or version (the
part after the column following the product). No argument will just
check for cpe existence.'

@staticmethod
def searchcpe(cpe_type=None, vendor=None, product=None, version=None):

    fields = [('type', cpe_type), ('vendor', vendor), ('product', product), ('version', version)]
    flt = dict(((field, value) for (field, value) in fields if (value is not None)))
    nflt = len(flt)
    if (nflt == 0):
        return {'cpes': {'$exists': True}}
    elif (nflt == 1):
        (field, value) = flt.popitem()
        return {('cpes.%s' % field): value}
    else:
        return {'cpes': {'$elemMatch': flt}}
