@ThreadSafe public interface MongoDatabase
Note: Additions to this interface will not be considered to break binary compatibility.
Modifier and Type | Method and Description |
---|---|
void |
createCollection(String collectionName)
Create a new collection with the given name.
|
void |
createCollection(String collectionName,
CreateCollectionOptions createCollectionOptions)
Create a new collection with the selected options
|
void |
dropDatabase()
Drops this database.
|
Document |
executeCommand(Object command)
Executes command in the context of the current database.
|
<T> T |
executeCommand(Object command,
Class<T> clazz)
Executes command in the context of the current database.
|
Document |
executeCommand(Object command,
ReadPreference readPreference)
Executes command in the context of the current database.
|
<T> T |
executeCommand(Object command,
ReadPreference readPreference,
Class<T> clazz)
Executes command in the context of the current database.
|
CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoDatabase.
|
MongoCollection<Document> |
getCollection(String collectionName)
Gets a collection.
|
<T> MongoCollection<T> |
getCollection(String collectionName,
Class<T> clazz)
Gets a collection, with a specific default document class.
|
String |
getName()
Gets the name of the database.
|
ReadPreference |
getReadPreference()
Get the read preference for the MongoDatabase.
|
WriteConcern |
getWriteConcern()
Get the write concern for the MongoDatabase.
|
MongoIterable<String> |
listCollectionNames()
Gets the names of all the collections in this database.
|
ListCollectionsFluent<Document> |
listCollections()
Finds all the collections in this database.
|
<C> ListCollectionsFluent<C> |
listCollections(Class<C> clazz)
Finds all the collections in this database.
|
MongoDatabase |
withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoDatabase instance with a different codec registry.
|
MongoDatabase |
withReadPreference(ReadPreference readPreference)
Create a new MongoDatabase instance with a different read preference.
|
MongoDatabase |
withWriteConcern(WriteConcern writeConcern)
Create a new MongoDatabase instance with a different write concern.
|
String getName()
CodecRegistry getCodecRegistry()
CodecRegistry
ReadPreference getReadPreference()
ReadPreference
WriteConcern getWriteConcern()
WriteConcern
MongoDatabase withCodecRegistry(CodecRegistry codecRegistry)
codecRegistry
- the new CodecRegistry
for the databaseMongoDatabase withReadPreference(ReadPreference readPreference)
readPreference
- the new ReadPreference
for the databaseMongoDatabase withWriteConcern(WriteConcern writeConcern)
writeConcern
- the new WriteConcern
for the databaseMongoCollection<Document> getCollection(String collectionName)
collectionName
- the name of the collection to return<T> MongoCollection<T> getCollection(String collectionName, Class<T> clazz)
T
- the type of the class to use instead of Document
.collectionName
- the name of the collection to returnclazz
- the default class to cast any documents returned from the database into.Document executeCommand(Object command)
command
- the command to be runDocument executeCommand(Object command, ReadPreference readPreference)
command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the command<T> T executeCommand(Object command, Class<T> clazz)
T
- the type of the class to use instead of Document
.command
- the command to be runclazz
- the default class to cast any documents returned from the database into.<T> T executeCommand(Object command, ReadPreference readPreference, Class<T> clazz)
T
- the type of the class to use instead of Document
.command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandclazz
- the default class to cast any documents returned from the database into.void dropDatabase()
MongoIterable<String> listCollectionNames()
ListCollectionsFluent<Document> listCollections()
<C> ListCollectionsFluent<C> listCollections(Class<C> clazz)
C
- the target document type of the iterable.clazz
- the class to decode each document intovoid createCollection(String collectionName)
collectionName
- the name for the new collection to createvoid createCollection(String collectionName, CreateCollectionOptions createCollectionOptions)
collectionName
- the name for the new collection to createcreateCollectionOptions
- various options for creating the collection