@Immutable public interface MongoClient extends Closeable
Instance of this class serve as factories for MongoDatabase
instances.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the client, which will close all underlying cached resources, including, for example,
sockets and background monitoring threads.
|
MongoDatabase |
getDatabase(String name)
Gets the database with the given name.
|
MongoClientSettings |
getSettings()
Gets the settings that this client uses to connect to server.
|
MongoIterable<String> |
listDatabaseNames()
Get a list of the database names
|
ListDatabasesIterable<Document> |
listDatabases()
Gets the list of databases
|
<TResult> ListDatabasesIterable<TResult> |
listDatabases(Class<TResult> resultClass)
Gets the list of databases
|
MongoDatabase getDatabase(String name)
name
- the name of the databaseIllegalArgumentException
- if databaseName is invalidMongoNamespace.checkDatabaseNameValidity(String)
void close()
close
in interface AutoCloseable
close
in interface Closeable
MongoClientSettings getSettings()
Note: MongoClientSettings
is immutable.
MongoIterable<String> listDatabaseNames()
ListDatabasesIterable<Document> listDatabases()
<TResult> ListDatabasesIterable<TResult> listDatabases(Class<TResult> resultClass)
TResult
- the type of the class to use instead of Document
.resultClass
- the class to cast the database documents to