class_docstr: This handler handles connection and execution of the MongoDB statements.
class_docstr_tok: ["This","handler","handles","connection","and","execution","of","the","MongoDB","statements","."]
docstr: input str or MongoQuery
  
  returns the records from the current recordset
docstr_tok: ["input","str","or","MongoQuery","returns","the","records","from","the","current","recordset"]
code: def native_query(self, query: [str, MongoQuery, dict]) -> Response:
      """
      input str or MongoQuery
  
      returns the records from the current recordset
      """
      if isinstance(query, str):
          query = MongodbParser().from_string(query)
  
      if isinstance(query, dict):
          # failback for previous api
  
          mquery = MongoQuery(query["collection"])
  
          for c in query["call"]:
              mquery.add_step(
                  {"method": c["method"], "args": c["args"]}
              )
  
          query = mquery
  
      collection = query.collection
      database = self.database
  
      con = self.connect()
  
      try:
          cursor = con[database][collection]
  
          for step in query.pipeline:
              fnc = getattr(cursor, step["method"])
              cursor = fnc(*step["args"])
  
          result = []
          if not isinstance(cursor, pymongo.results.UpdateResult):
              for row in cursor:
                  result.append(
                      self.flatten(row, level=self.flatten_level)
                  )
  
          if len(result) > 0:
              df = pd.DataFrame(result)
          else:
              columns = list(
                  self.get_columns(collection).data_frame.Field
              )
              df = pd.DataFrame([], columns=columns)
  
          response = Response(RESPONSE_TYPE.TABLE, df)
  
      except Exception as e:
          logger.error(
              f"Error running query: {query} on {self.database}.{collection}!"
          )
          response = Response(RESPONSE_TYPE.ERROR, error_message=str(e))
  
      return response
  
imports: import re
  import time
  from collections import OrderedDict
  from bson import ObjectId
  import certifi
  import pandas
  import pymongo
  from pymongo import MongoClient
  from mindsdb_sql.parser.ast.base import ASTNode
  from mindsdb.utilities import log
  from mindsdb.integrations.libs.base import DatabaseHandler
  from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE
  from mindsdb.integrations.libs.response import HandlerStatusResponse, HandlerResponse, RESPONSE_TYPE
  from .utils.mongodb_render import MongodbRender
  from mindsdb.api.mongo.utilities.mongodb_query import MongoQuery
  from mindsdb.api.mongo.utilities.mongodb_parser import MongodbParser
label_desc: Use image node_id 7 for calling the MongoDBHandler obj's underlying member method code with example usage: obj.native_query(query) and returns: response