code: def find_to_ast(query, database):
      mongoToAst = MongoToAst()
  
      collection = [database, query["find"]]
  
      if not query.get("singleBatch") and "collection" in query.get(
          "filter"
      ):
          # JOIN mode
  
          # upper query
          ast_query = mongoToAst.find(
              collection=collection,
              projection=query.get("projection"),
              sort=query.get("sort"),
              limit=query.get("limit"),
              skip=query.get("skip"),
          )
  
          # table_query
          collection = query["filter"]["collection"]
          filter = query["filter"].get("query", {})
          table_select = mongoToAst.find(
              collection=collection,
              filter=filter,
          )
          table_select.parentheses = True
          table_select.alias = Identifier(query["filter"]["collection"])
          table_select.alias.parts = [table_select.alias.parts[-1]]
          if "limit" in query:
              table_select.limit = Constant(query["limit"])
  
          modifiers = query["filter"].get("modifiers")
          if modifiers is not None and hasattr(ast_query, "modifiers"):
              for modifier in modifiers:
                  table_select.modifiers.append(modifier)
  
          # convert to join
          right_table = ast_query.from_table
  
          ast_join = Join(
              left=table_select, right=right_table, join_type="join"
          )
          ast_query.from_table = ast_join
  
      else:
          # is single table
          ast_query = mongoToAst.find(
              collection=collection,
              filter=query.get("filter"),
              projection=query.get("projection"),
              sort=query.get("sort"),
              limit=query.get("limit"),
              skip=query.get("skip"),
          )
          modifiers = query["filter"].get("modifiers")
          if modifiers is not None and hasattr(ast_query, "modifiers"):
              for modifier in modifiers:
                  ast_query.modifiers.append(modifier)
      return ast_query
  
file_path: mindsdb/mindsdb/api/mongo/responders/find.py
imports: from bson.int64 import Int64
  from mindsdb_sql.parser.ast import Join, Select, Identifier, Describe, Show, Constant
  import mindsdb.api.mongo.functions
  from mindsdb.api.mongo.classes import Responder
  from mindsdb.api.mongo.utilities.mongodb_ast import MongoToAst
  from mindsdb.interfaces.jobs.jobs_controller import JobsController
  from mindsdb.api.mongo.classes.query_sql import run_sql_command
label_desc: Use image node_id 1 for calling a global function with example usage: find_to_ast(query, database) and returns: ast_query