@ThreadSafe public interface MongoDatabase
Note: Additions to this interface will not be considered to break binary compatibility.
Modifier and Type | Method | Description |
---|---|---|
void |
createCollection(ClientSession clientSession,
String collectionName) |
Create a new collection with the given name.
|
void |
createCollection(ClientSession clientSession,
String collectionName,
CreateCollectionOptions createCollectionOptions) |
Create a new collection with the selected options
|
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(ClientSession clientSession,
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(ClientSession clientSession,
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 |
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.
|
void |
drop(ClientSession clientSession) |
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.
|
MongoIterable<String> |
listCollectionNames(ClientSession clientSession) |
Gets the names of all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections() |
Finds all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections(ClientSession clientSession) |
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(ClientSession clientSession,
Class<TResult> resultClass) |
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(Class<TResult> resultClass) |
Finds all the collections in this database.
|
Document |
runCommand(ClientSession clientSession,
Bson command) |
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
Document |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference) |
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference,
Class<TResult> resultClass) |
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(ClientSession clientSession,
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) |
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.
|
<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() . |
ChangeStreamIterable<Document> |
watch() |
Creates a change stream for this database.
|
ChangeStreamIterable<Document> |
watch(ClientSession clientSession) |
Creates a change stream for this database.
|
<TResult> ChangeStreamIterable<TResult> |
watch(ClientSession clientSession,
Class<TResult> resultClass) |
Creates a change stream for this database.
|
ChangeStreamIterable<Document> |
watch(ClientSession clientSession,
List<? extends Bson> pipeline) |
Creates a change stream for this database.
|
<TResult> ChangeStreamIterable<TResult> |
watch(ClientSession clientSession,
List<? extends Bson> pipeline,
Class<TResult> resultClass) |
Creates a change stream for this database.
|
<TResult> ChangeStreamIterable<TResult> |
watch(Class<TResult> resultClass) |
Creates a change stream for this database.
|
ChangeStreamIterable<Document> |
watch(List<? extends Bson> pipeline) |
Creates a change stream for this database.
|
<TResult> ChangeStreamIterable<TResult> |
watch(List<? extends Bson> pipeline,
Class<TResult> resultClass) |
Creates a change stream for this database.
|
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 returnIllegalArgumentException
- if collectionName is invalidMongoNamespace.checkCollectionNameValidity(String)
<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 class to decode each document 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 class to decode each document intoDocument runCommand(ClientSession clientSession, Bson command)
ReadPreference.primary()
.clientSession
- the client session with which to associate this operationcommand
- the command to be runDocument runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference)
clientSession
- the client session with which to associate this operationcommand
- the command to be runreadPreference
- the ReadPreference
to be used when executing the command<TResult> TResult runCommand(ClientSession clientSession, Bson command, Class<TResult> resultClass)
ReadPreference.primary()
.TResult
- the type of the class to use instead of Document
.clientSession
- the client session with which to associate this operationcommand
- the command to be runresultClass
- the class to decode each document into<TResult> TResult runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, Class<TResult> resultClass)
TResult
- the type of the class to use instead of Document
.clientSession
- the client session with which to associate this operationcommand
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandresultClass
- the class to decode each document intovoid drop()
void drop(ClientSession clientSession)
clientSession
- the client session with which to associate this operationMongoIterable<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 intoMongoIterable<String> listCollectionNames(ClientSession clientSession)
clientSession
- the client session with which to associate this operationListCollectionsIterable<Document> listCollections(ClientSession clientSession)
clientSession
- the client session with which to associate this operation<TResult> ListCollectionsIterable<TResult> listCollections(ClientSession clientSession, Class<TResult> resultClass)
TResult
- the target document type of the iterable.clientSession
- the client session with which to associate this operationresultClass
- 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 createCollection(ClientSession clientSession, String collectionName)
clientSession
- the client session with which to associate this operationcollectionName
- the name for the new collection to createvoid createCollection(ClientSession clientSession, String collectionName, CreateCollectionOptions createCollectionOptions)
clientSession
- the client session with which to associate this operationcollectionName
- 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 viewvoid createView(ClientSession clientSession, String viewName, String viewOn, List<? extends Bson> pipeline)
clientSession
- the client session with which to associate this operationviewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewvoid createView(ClientSession clientSession, String viewName, String viewOn, List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
clientSession
- the client session with which to associate this operationviewName
- 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 viewChangeStreamIterable<Document> watch()
<TResult> ChangeStreamIterable<TResult> watch(Class<TResult> resultClass)
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intoChangeStreamIterable<Document> watch(List<? extends Bson> pipeline)
pipeline
- the aggregation pipeline to apply to the change stream.<TResult> ChangeStreamIterable<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass)
TResult
- the target document type of the iterable.pipeline
- the aggregation pipeline to apply to the change streamresultClass
- the class to decode each document intoChangeStreamIterable<Document> watch(ClientSession clientSession)
clientSession
- the client session with which to associate this operation<TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, Class<TResult> resultClass)
TResult
- the target document type of the iterable.clientSession
- the client session with which to associate this operationresultClass
- the class to decode each document intoChangeStreamIterable<Document> watch(ClientSession clientSession, List<? extends Bson> pipeline)
clientSession
- the client session with which to associate this operationpipeline
- the aggregation pipeline to apply to the change stream.<TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass)
TResult
- the target document type of the iterable.clientSession
- the client session with which to associate this operationpipeline
- the aggregation pipeline to apply to the change streamresultClass
- the class to decode each document into