Python function that takes a json object returns mongodb query object Python function that takes a json object returns mongodb query object json json

Python function that takes a json object returns mongodb query object


Hopefully I understood the question right

def splitToItems(query, items={}):    q = {}    if 'and' in query:        l = []        for item in query['and']:           l.append(splitToItems(item))        q["$and"] = l    if 'or' in query:        l = []        for item in query['or']:           l.append(splitToItems(item))        q["$or"] = l    if q:        return q    return queryprint(splitToItems(query))

Does this solve your problem?