code: private DB getConnection()
      {
  
          PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata().getPersistenceUnitMetadata(
                  getPersistenceUnit());
  
          Properties props = puMetadata.getProperties();
          String contactNode = null;
          String defaultPort = null;
          String keyspace = null;
          String poolSize = null;
          if (externalProperties != null)
          {
              contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES);
              defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT);
              keyspace = (String) externalProperties.get(PersistenceProperties.KUNDERA_KEYSPACE);
              poolSize = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE);
          }
          if (contactNode == null)
          {
              contactNode = (String) props.get(PersistenceProperties.KUNDERA_NODES);
          }
          if (defaultPort == null)
          {
              defaultPort = (String) props.get(PersistenceProperties.KUNDERA_PORT);
          }
          if (keyspace == null)
          {
              keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE);
          }
          if (poolSize == null)
          {
              poolSize = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE);
          }
  
          onValidation(contactNode, defaultPort);
  
          List<ServerAddress> addrs = new ArrayList<>();
  
          MongoClient mongo = null;
          try
          {
              mongo = onSetMongoServerProperties(contactNode, defaultPort, poolSize, addrs,
                      MongoDBUtils.fetchCredentials(props, externalProperties));
  
              logger.info("Connected to mongodb at " + contactNode + " on port " + defaultPort);
          }
          catch (NumberFormatException e)
          {
              logger.error("Invalid format for MONGODB port, Unale to connect!" + "; Caused by:" + e.getMessage());
              throw new ClientLoaderException(e);
          }
          catch (MongoException e)
          {
              logger.error("Unable to connect to MONGODB; Caused by:" + e.getMessage());
              throw new ClientLoaderException(e);
          }
          return mongo.getDB(keyspace);
      }
docs: Gets the connection.
  
  @return the connection