function parseWhere(root) {
    const operator = Object.keys(root)[0];

    // extract leaf binary expressions
    if (operator === 'AND') {
        const e1 = parseWhere(root[operator][0]);
        const e2 = parseWhere(root[operator][1]);

        return { '$and' : [
            e1,
            e2,
        ] };
    } else if (operator === 'OR') {
        const e1 = parseWhere(root[operator][0]);
        const e2 = parseWhere(root[operator][1]);

        return  { '$or' : [
            e1,
            e2,
        ] };
    }
    const field = root[operator][0];
    const value = root[operator][1];
    const expr = exprMapper[operator];
    const obj = {};

    if (operator === 'LIKE') {
        obj[`value.${field}`] = parseLikeExpression(value);
    } else {
        obj[`value.${field}`] = { [expr]: value };
    }

    return obj;
}
A helper object to map SQL-like naming to MongoDB query syntax