@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 |
createView(String viewName,
String viewOn,
List<? extends Bson> pipeline)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
createView(String viewName,
String viewOn,
List<? extends Bson> pipeline,
CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
drop()
Drops this database.
|
CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoDatabase.
|
MongoCollection<Document> |
getCollection(String collectionName)
Gets a collection.
|
<TDocument> |
getCollection(String collectionName,
Class<TDocument> documentClass)
Gets a collection, with a specific default document class.
|
String |
getName()
Gets the name of the database.
|
ReadConcern |
getReadConcern()
Get the read concern for the MongoDatabase.
|
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.
|
ListCollectionsIterable<Document> |
listCollections()
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(Class<TResult> resultClass)
Finds all the collections in this database.
|
Document |
runCommand(Bson command)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
<TResult> TResult |
runCommand(Bson command,
Class<TResult> resultClass)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
Document |
runCommand(Bson command,
ReadPreference readPreference)
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(Bson command,
ReadPreference readPreference,
Class<TResult> resultClass)
Executes the given command in the context of the current database with the given read preference.
|
MongoDatabase |
withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoDatabase instance with a different codec registry.
|
MongoDatabase |
withReadConcern(ReadConcern readConcern)
Create a new MongoDatabase instance with a different read concern.
|
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
ReadConcern getReadConcern()
ReadConcern
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 databaseMongoDatabase withReadConcern(ReadConcern readConcern)
readConcern
- the new ReadConcern
for the databaseMongoCollection<Document> getCollection(String collectionName)
collectionName
- the name of the collection to return<TDocument> MongoCollection<TDocument> getCollection(String collectionName, Class<TDocument> documentClass)
TDocument
- the type of the class to use instead of Document
.collectionName
- the name of the collection to returndocumentClass
- the default class to cast any documents returned from the database into.Document runCommand(Bson command)
ReadPreference.primary()
.command
- the command to be runDocument runCommand(Bson command, ReadPreference readPreference)
command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the command<TResult> TResult runCommand(Bson command, Class<TResult> resultClass)
ReadPreference.primary()
.TResult
- the type of the class to use instead of Document
.command
- the command to be runresultClass
- the default class to cast any documents returned from the database into.<TResult> TResult runCommand(Bson command, ReadPreference readPreference, Class<TResult> resultClass)
TResult
- the type of the class to use instead of Document
.command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandresultClass
- the default class to cast any documents returned from the database into.void drop()
MongoIterable<String> listCollectionNames()
ListCollectionsIterable<Document> listCollections()
<TResult> ListCollectionsIterable<TResult> listCollections(Class<TResult> resultClass)
TResult
- the target document type of the iterable.resultClass
- 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 collectionvoid createView(String viewName, String viewOn, List<? extends Bson> pipeline)
viewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewvoid createView(String viewName, String viewOn, List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
viewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewcreateViewOptions
- various options for creating the view