Get the database name from the given mongodb uri.
@param {string} uri the mongodb uri
@returns {string} the name of the mongodb database
346803
function getDbName(uri) {
  var parsedMongooseUri = mongoUriParser.parse(uri);
  var dbName = parsedMongooseUri.database;
  return dbName;
}
682098
function(uri) {
    const scheme = this.getScheme(uri);

    if (PUBLIC === scheme || TEMPORARY === scheme) {
      return '/' + this.resolvePath(uri);
    }

    return uri;
  }
119210
def getDbNames(self):
		""""""

		request = []
		request.append(uu({'-dbnames': '' }))

		result = self._doRequest(request)
		result = FMResultset.FMResultset(result)

		dbNames = []
		for dbName in result.resultset:
			dbNames.append(string.lower(dbName['DATABASE_NAME']))

		return dbNames
1244361
def parse_db_uri(db_uri)
      uri = URI.parse(db_uri)
    
      db_config = {
        :adapter => uri.scheme,
        :database => uri.path[1..-1],
        :host => uri.host
      }
    
      if uri.user
        db_config[:username] = uri.user
        db_config[:password] = uri.password if uri.password
      end
      db_config[:port] = uri.port if uri.port
    
      db_config
    end
143092
function MongoStore(uri, options) {
        var self = this;

        this.options = options || (options = {});
        options.collectionName = options.collectionName || 'sessions';
        // 1 day
        options.ttl = options.ttl || 24 * 60 * 60 * 1000;
        // 60 s
        options.cleanupInterval = options.cleanupInterval || 60 * 1000;
        options.server = options.server || {};
        options.server.auto_reconnect = options.server.auto_reconnect != null ? options.server.auto_reconnect : true;

        this._error = function(err) {
            if (err) { self.emit('error', err); }
        };

        // It's a Db instance.
        if (uri.collection) {
            this.db = uri;
            this._setup();
        } else {
            MongoClient.connect(uri, options, function(err, db) {
                if (err) { return self._error(err); }
                self.db = db;
                self._setup();
            });
        }
    }
571046
def get_database_name(self):
        
        uri_dict = uri_parser.parse_uri(self.host)
        database = uri_dict.get('database', None)
        if not database:
            raise "database name is missing"
        return database
103688
def _parse_uri(cls, server, sanitize_username=False):
        
        parsed = pymongo.uri_parser.parse_uri(server)

        username = parsed.get('username')
        password = parsed.get('password')
        db_name = parsed.get('database')
        nodelist = parsed.get('nodelist')
        auth_source = parsed.get('options', {}).get('authsource')

        # Remove password (and optionally username) from sanitized server URI.
        # To ensure that the `replace` works well, we first need to url-decode the raw server string
        # since the password parsed by pymongo is url-decoded
        decoded_server = unquote_plus(server)
        clean_server_name = decoded_server.replace(password, "*" * 5) if password else decoded_server

        if sanitize_username and username:
            username_pattern = u"{}[@:]".format(re.escape(username))
            clean_server_name = re.sub(username_pattern, "", clean_server_name)

        return username, password, db_name, nodelist, clean_server_name, auth_source
921903
public static String getDatabaseName() {
        String databaseName = getMetaDataString(METADATA_DATABASE);

        if (databaseName == null) {
            databaseName = DATABASE_DEFAULT_NAME;
        }

        return databaseName;
    }
40504
public static String getName(URI uri) {
        if (uri == null) {
            throw MESSAGES.nullArgument("uri");
        }
        String name = uri.getPath();
        if (name != null) {
            // TODO: Not correct for certain uris like jar:...!/
            int lastSlash = name.lastIndexOf('/');
            if (lastSlash > 0) { name = name.substring(lastSlash + 1); }
        }
        return name;
    }
1216839
function getPathnameFromUrl (u) {
	const pathname = url.parse(u).pathname;
	try {
		return decodeURI(pathname);
	} catch (e) {
		return pathname;
	}
}
569372
public function getDefaultDatabaseName()
    {
        if ($this->_defaultDatabaseName === null) {
            if (preg_match('/^mongodb:\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) {
                $this->_defaultDatabaseName = $matches[1];
            } else {
                throw new InvalidConfigException("Unable to determine default database name from dsn.");
            }
        }

        return $this->_defaultDatabaseName;
    }
1118015
String getCollectionName(String url) {
        final String SEPARATOR = "\\";
        String cell = null;
        String node = null;
        String serverName = null;
        int index = -1;

        if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_WAS.entering(methodClassName, methodNames[GET_COLLECTION_NAME], "url: " + url);
        }

        //lets look to see if we can use the url.  This most likely means the native driver
        if (url != null && url.indexOf("jdbc:db2") != -1) {
            String collection = url;

            index = collection.indexOf(";");
            if (index != -1) {
                collection = collection.substring(0, index);
            }
            index = collection.indexOf("//");
            if (index != -1) {
                collection = collection.substring(index + 2);
            }
            index = collection.indexOf("/");
            if (index != -1) {
                collection = collection.substring(index + 1).trim();
                if (collection.length() != 0) {
                    as400_collection = collection;
                }
            }
        } else {
            //using toolbox driver

            //            try {
            //            	/*
            //                String unformatted = com.ibm.websphere.runtime.ServerName.getFullName();
            //
            //                if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled()&&LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINE)) {
            //                    LoggingUtil.SESSION_LOGGER_WAS.logp(Level.FINE, methodClassName, methodNames[GET_COLLECTION_NAME], "Full server name retrieved: " + unformatted);
            //                }
            //
            //                //we need everything or nothing, so do no checking here until we're done.
            //                //if we something winds up null, then we're toast anyway, so take the exception
            //                //and use the defaults in the catch below.
            //                index = unformatted.indexOf(SEPARATOR);
            //                cell = unformatted.substring(0, index);
            //                unformatted = unformatted.substring(index + SEPARATOR.length());
            //
            //                index = unformatted.indexOf(SEPARATOR);
            //                node = unformatted.substring(0, index);
            //
            //                serverName = unformatted.substring(index + SEPARATOR.length());
            //
            //                if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled()&&LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINE)) {
            //                    LoggingUtil.SESSION_LOGGER_WAS.logp(Level.FINE, methodClassName, methodNames[GET_COLLECTION_NAME], "Using cell name: " + cell);
            //                    LoggingUtil.SESSION_LOGGER_WAS.logp(Level.FINE, methodClassName, methodNames[GET_COLLECTION_NAME], "Using node name: " + node);
            //                    LoggingUtil.SESSION_LOGGER_WAS.logp(Level.FINE, methodClassName, methodNames[GET_COLLECTION_NAME], "Using server name: " + serverName);
            //                }
            //
            //                if ((cell == null) || (node == null) || (serverName == null))
            //                    throw new Exception("Unable to retrieve cell, node, or serverName.");
            //
            //                com.ibm.ws.runtime.service.Repository repository = com.ibm.ws.runtime.service.RepositoryFactory.createRepository(System.getProperty("user.install.root") + "/config", cell, node, serverName);
            //
            //                  */
            //                // com.ibm.ws.runtime.service.Repository repository = com.ibm.ws.runtime.service.RepositoryFactory.createRepository(System.getProperty("user.install.root") + "/config", cell, node, serverName);
            //                // PK78174 this instanceof com.ibm.wsspi.runtime.component.WsComponent
            //                Repository repository = (Repository) WsServiceRegistry.getService(this, Repository.class);
            //
            //                if (repository == null)
            //                    throw new Exception("Unable to acquire a reference to the repository.");
            //
            //                String jndiDSName = _smc.getJNDIDataSourceName();
            //                if ((as400_collection = retrieveDBSessionCollection(repository, com.ibm.ws.runtime.service.ConfigRoot.SERVER, jndiDSName)) == null) {
            //                    if ((as400_collection = retrieveDBSessionCollection(repository, com.ibm.ws.runtime.service.ConfigRoot.NODE, jndiDSName)) == null) {
            //                        if ((as400_collection = retrieveDBSessionCollection(repository, com.ibm.ws.runtime.service.ConfigRoot.CELL, jndiDSName)) == null) {
            //                        	if ((as400_collection = retrieveDBSessionCollection(repository, com.ibm.ws.runtime.service.ConfigRoot.CLUSTER, jndiDSName)) == null) {
            //                        		throw new Exception("DataSource not configured with JNDI name: " + jndiDSName);
            //                        	}
            //                        }
            //                    }
            //                }
            //            } catch (Exception ex) {
            //                LoggingUtil.SESSION_LOGGER_WAS.logp(Level.WARNING, methodClassName, methodNames[GET_COLLECTION_NAME], "CommonMessage.exception", ex);
            //            }
        }

        if (as400_collection == null) {
            String installLibrary = System.getProperty("was.install.library");
            if (installLibrary == null) {
                LoggingUtil.SESSION_LOGGER_WAS.logp(Level.WARNING, methodClassName, methodNames[GET_COLLECTION_NAME], "CommonMessage.miscData",
                                                    "was.install.library not set.  Using collection QEJBASSN for session persistance.");
                as400_collection = "QEJBASSN";
            } else {
                LoggingUtil.SESSION_LOGGER_WAS.logp(Level.WARNING, methodClassName, methodNames[GET_COLLECTION_NAME], "CommonMessage.miscData",
                                                    "using was.install.library to derive collection name for session persistance.");
                as400_collection = installLibrary + "SN";
                if (as400_collection.length() > 10) {
                    as400_collection = as400_collection.substring(0, 10);
                }
            }
        }
        if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINER)) {
            LoggingUtil.SESSION_LOGGER_WAS.exiting(methodClassName, methodNames[GET_COLLECTION_NAME], "Session Persistance will use the collection: " + as400_collection);
        }
        return as400_collection;
    }
656629
def _format_mongodb_uri(parsed_uri):
    
    user_pass = ''
    if parsed_uri.get('username') and parsed_uri.get('password'):
        user_pass = '{username!s}:{password!s}@'.format(**parsed_uri)

    _nodes = []
    for host, port in parsed_uri.get('nodelist'):
        if ':' in host and not host.endswith(']'):
            # IPv6 address without brackets
            host = '[{!s}]'.format(host)
        if port == 27017:
            _nodes.append(host)
        else:
            _nodes.append('{!s}:{!s}'.format(host, port))
    nodelist = ','.join(_nodes)

    options = ''
    if parsed_uri.get('options'):
        _opt_list = []
        for key, value in parsed_uri.get('options').items():
            if isinstance(value, bool):
                value = str(value).lower()
            _opt_list.append('{!s}={!s}'.format(key, value))
        options = '?' + '&'.join(_opt_list)

    db_name = parsed_uri.get('database') or ''

    res = "mongodb://{user_pass!s}{nodelist!s}/{db_name!s}{options!s}".format(
        user_pass=user_pass,
        nodelist=nodelist,
        db_name=db_name,
        # collection is ignored
        options=options)
    return res
941996
public String determineDatabaseName() {
		if (this.generateUniqueName) {
			if (this.uniqueName == null) {
				this.uniqueName = UUID.randomUUID().toString();
			}
			return this.uniqueName;
		}
		if (StringUtils.hasLength(this.name)) {
			return this.name;
		}
		if (this.embeddedDatabaseConnection != EmbeddedDatabaseConnection.NONE) {
			return "testdb";
		}
		return null;
	}
1370460
def database(self, database_name):
        
        if database_name and MongoDB.valid_mongodb_name(database_name):
            self._database = self.client[database_name]
        else:
            raise ShellError(f"'{database_name}' is not a valid database name")
352393
function baseStringUri(uri) {
    var parsed = url.parse(uri);

    //  The port MUST be included if it is not the default port for the
    //  scheme, and MUST be excluded if it is the default.
    if (parsed.protocol === 'https:/') {
        parsed.host = parsed.host.replace(/:443$/, '');
    } else if (parsed.protocol === 'http:/') {
        parsed.host = parsed.host.replace(/:80$/, '');
    }

    return url.format({
        protocol: parsed.protocol,
        host: parsed.host,
        auth: parsed.auth,
        pathname: parsed.pathname
    });
}
705418
public function getDbName($id)
    {
        if (!$this->dbNames[$id]) {
            $record = wei()->appRecord()->findById($id);
            $this->dbNames[$id] = $record['name'];
        }

        return $this->dbNames[$id];
    }