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","."]
code: def flatten(self, row, level=0):
      # move sub-keys to upper level
  
      add = {}
      del_keys = []
      edit_keys = {}
      for k, v in row.items():
          # convert objectId to string
          if isinstance(v, ObjectId):
              edit_keys[k] = str(v)
          if level > 0:
              if isinstance(v, dict):
                  for k2, v2 in self.flatten(
                      v, level=level - 1
                  ).items():
                      add[f"{k}.{k2}"] = v2
                  del_keys.append(k)
      if add:
          row.update(add)
      for key in del_keys:
          del row[key]
      if edit_keys:
          row.update(edit_keys)
  
      return row
  
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 8 for calling the MongoDBHandler obj's underlying member method code with example usage: obj.flatten(row, level) and returns: row