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 connect(self):
      kwargs = {}
      if isinstance(self.user, str) and len(self.user) > 0:
          kwargs["username"] = self.user
  
      if isinstance(self.password, str) and len(self.password) > 0:
          kwargs["password"] = self.password
  
      if re.match(r"/?.*tls=true", self.host.lower()):
          kwargs["tls"] = True
  
      if re.match(r"/?.*tls=false", self.host.lower()):
          kwargs["tls"] = False
  
      if (
          re.match(r".*.mongodb.net", self.host.lower())
          and kwargs.get("tls", None) is None
      ):
          kwargs["tlsCAFile"] = certifi.where()
          if kwargs.get("tls", None) is None:
              kwargs["tls"] = True
  
      connection = MongoClient(self.host, port=self.port, **kwargs)
      # detect database from connection
      if self.database is None:
          self.database = connection.get_database().name
  
      self.is_connected = True
      self.connection = connection
      return self.connection
  
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 3 for calling the MongoDBHandler obj's underlying member method code with example usage: obj.connect() and returns: self