@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,
SingleResultCallback<Void> callback) |
Create a new collection with the given name.
|
void |
createCollection(ClientSession clientSession,
String collectionName,
CreateCollectionOptions options,
SingleResultCallback<Void> callback) |
Create a new collection with the selected options
|
void |
createCollection(String collectionName,
SingleResultCallback<Void> callback) |
Create a new collection with the given name.
|
void |
createCollection(String collectionName,
CreateCollectionOptions options,
SingleResultCallback<Void> callback) |
Create a new collection with the selected options
|
void |
createView(ClientSession clientSession,
String viewName,
String viewOn,
List<? extends Bson> pipeline,
SingleResultCallback<Void> callback) |
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,
SingleResultCallback<Void> callback) |
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,
SingleResultCallback<Void> callback) |
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,
SingleResultCallback<Void> callback) |
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
drop(ClientSession clientSession,
SingleResultCallback<Void> callback) |
Drops this database.
|
void |
drop(SingleResultCallback<Void> callback) |
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.
|
void |
runCommand(ClientSession clientSession,
Bson command,
SingleResultCallback<Document> callback) |
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
void |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference,
SingleResultCallback<Document> callback) |
Executes the given command in the context of the current database with the given read preference.
|
<TResult> void |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference,
Class<TResult> resultClass,
SingleResultCallback<TResult> callback) |
Executes the given command in the context of the current database with the given read preference.
|
<TResult> void |
runCommand(ClientSession clientSession,
Bson command,
Class<TResult> resultClass,
SingleResultCallback<TResult> callback) |
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
void |
runCommand(Bson command,
SingleResultCallback<Document> callback) |
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
void |
runCommand(Bson command,
ReadPreference readPreference,
SingleResultCallback<Document> callback) |
Executes the given command in the context of the current database with the given read preference.
|
<TResult> void |
runCommand(Bson command,
ReadPreference readPreference,
Class<TResult> resultClass,
SingleResultCallback<TResult> callback) |
Executes the given command in the context of the current database with the given read preference.
|
<TResult> void |
runCommand(Bson command,
Class<TResult> resultClass,
SingleResultCallback<TResult> callback) |
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.void runCommand(Bson command, SingleResultCallback<Document> callback)
ReadPreference.primary()
.command
- the command to be runcallback
- the callback that is passed the command resultvoid runCommand(Bson command, ReadPreference readPreference, SingleResultCallback<Document> callback)
command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandcallback
- the callback that is passed the command result<TResult> void runCommand(Bson command, Class<TResult> resultClass, SingleResultCallback<TResult> callback)
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.callback
- the callback that is passed the command result<TResult> void runCommand(Bson command, ReadPreference readPreference, Class<TResult> resultClass, SingleResultCallback<TResult> callback)
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.callback
- the callback that is passed the command resultvoid runCommand(ClientSession clientSession, Bson command, SingleResultCallback<Document> callback)
ReadPreference.primary()
.clientSession
- the client session with which to associate this operationcommand
- the command to be runcallback
- the callback that is passed the command resultvoid runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, SingleResultCallback<Document> callback)
clientSession
- the client session with which to associate this operationcommand
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandcallback
- the callback that is passed the command result<TResult> void runCommand(ClientSession clientSession, Bson command, Class<TResult> resultClass, SingleResultCallback<TResult> callback)
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 default class to cast any documents returned from the database into.callback
- the callback that is passed the command result<TResult> void runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, Class<TResult> resultClass, SingleResultCallback<TResult> callback)
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 default class to cast any documents returned from the database into.callback
- the callback that is passed the command resultvoid drop(SingleResultCallback<Void> callback)
callback
- the callback that is completed once the database has been droppedvoid drop(ClientSession clientSession, SingleResultCallback<Void> callback)
callback
- the callback that is completed once the database has been droppedclientSession
- the client session with which to associate this operationMongoIterable<String> listCollectionNames()
MongoIterable<String> listCollectionNames(ClientSession clientSession)
clientSession
- the client session with which to associate this operationListCollectionsIterable<Document> listCollections()
<TResult> ListCollectionsIterable<TResult> listCollections(Class<TResult> resultClass)
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intoListCollectionsIterable<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, SingleResultCallback<Void> callback)
collectionName
- the name for the new collection to createcallback
- the callback that is completed once the collection has been createdvoid createCollection(String collectionName, CreateCollectionOptions options, SingleResultCallback<Void> callback)
collectionName
- the name for the new collection to createoptions
- various options for creating the collectioncallback
- the callback that is completed once the collection has been createdvoid createCollection(ClientSession clientSession, String collectionName, SingleResultCallback<Void> callback)
clientSession
- the client session with which to associate this operationcollectionName
- the name for the new collection to createcallback
- the callback that is completed once the collection has been createdvoid createCollection(ClientSession clientSession, String collectionName, CreateCollectionOptions options, SingleResultCallback<Void> callback)
clientSession
- the client session with which to associate this operationcollectionName
- the name for the new collection to createoptions
- various options for creating the collectioncallback
- the callback that is completed once the collection has been createdvoid createView(String viewName, String viewOn, List<? extends Bson> pipeline, SingleResultCallback<Void> callback)
viewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewcallback
- the callback that is completed once the collection has been createdvoid createView(String viewName, String viewOn, List<? extends Bson> pipeline, CreateViewOptions createViewOptions, SingleResultCallback<Void> callback)
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 viewcallback
- the callback that is completed once the collection has been createdvoid createView(ClientSession clientSession, String viewName, String viewOn, List<? extends Bson> pipeline, SingleResultCallback<Void> callback)
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 viewcallback
- the callback that is completed once the collection has been createdvoid createView(ClientSession clientSession, String viewName, String viewOn, List<? extends Bson> pipeline, CreateViewOptions createViewOptions, SingleResultCallback<Void> callback)
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 viewcallback
- the callback that is completed once the collection has been createdChangeStreamIterable<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