class_docstr: Converts query mongo to AST format
class_docstr_tok: ["Converts","query","mongo","to","AST","format"]
code: def convert_filter(self, filter):
      cond_ops = {
          "$and": "and",
          "$or": "or",
      }
  
      ast_filter = None
      for k, v in filter.items():
          if k in ("$or", "$and"):
              # suppose it is one key in dict
  
              op = cond_ops[k]
  
              nodes = []
              for cond in v:
                  nodes.append(self.convert_filter(cond))
  
              if len(nodes) == 1:
                  return nodes[0]
  
              # compose as tree
              arg1 = nodes[0]
              for node in nodes[1:]:
                  arg1 = BinaryOperation(op=op, args=[arg1, node])
  
              return arg1
          if k in ("$where", "$expr"):
              # try to parse simple expression like 'this.saledate > this.latest'
              return MongoWhereParser(v).to_ast()
  
          # is filter
          arg1 = Identifier(parts=[k])
  
          op, value = self.handle_filter(v)
          arg2 = Constant(value=value)
          ast_com = BinaryOperation(op=op, args=[arg1, arg2])
          if ast_filter is None:
              ast_filter = ast_com
          else:
              ast_filter = BinaryOperation(
                  op="and", args=[ast_filter, ast_com]
              )
      return ast_filter
  
file_path: mindsdb/mindsdb/api/mongo/utilities/mongodb_ast.py
imports: import re
  import ast
  import typing
  from mindsdb_sql.parser.ast import OrderBy, Identifier, Star, Select, Constant, BinaryOperation, Tuple, Latest
label_desc: Use image node_id 3 for calling the MongoToAst obj's underlying member method code with example usage: obj.convert_filter(filter) and returns: ast_filter, arg1, MongoWhereParser, nodes