class_docstr: Converts query mongo to AST format
class_docstr_tok: ["Converts","query","mongo","to","AST","format"]
code: def find(
      self,
      collection: t.Union[list, str],
      filter=None,
      sort=None,
      projection=None,
      limit=None,
      skip=None,
      **kwargs,
  ):
      # https://www.mongodb.com/docs/v4.2/reference/method/db.collection.find/
  
      order_by = None
      if sort is not None:
          # sort is dict
          order_by = []
          for col, direction in sort.items():
              order_by.append(
                  OrderBy(
                      field=Identifier(parts=[col]),
                      direction="DESC" if direction == -1 else "ASC",
                  )
              )
  
      if projection is not None:
          targets = []
          for col, alias in projection.items():
              # it is only identifiers
              if isinstance(alias, str):
                  alias = Identifier(parts=[alias])
              else:
                  alias = None
              targets.append(Identifier(path_str=col, alias=alias))
      else:
          targets = [Star()]
  
      where = None
      if filter is not None:
          where = self.convert_filter(filter)
  
      # convert to AST node
      #   collection can be string or list
      if isinstance(collection, list):
          collection = Identifier(parts=collection)
      else:
          collection = Identifier(path_str=collection)
  
      node = Select(
          targets=targets,
          from_table=collection,
          where=where,
          order_by=order_by,
      )
      if limit is not None:
          node.limit = Constant(value=limit)
  
      if skip is not None and skip != 0:
          node.offset = Constant(value=skip)
  
      return node
  
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 2 for calling the MongoToAst obj's underlying member method code with example usage: obj.find(collection, filter, sort, projection, limit, skip) and returns: node