Interface MongoDatabase
Note: Additions to this interface will not be considered to break binary compatibility.
- Since:
- 1.0
- 
Method SummaryModifier and TypeMethodDescriptionaggregate(ClientSession clientSession, List<? extends Bson> pipeline) Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.<TResult> AggregatePublisher<TResult>aggregate(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass) Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.<TResult> AggregatePublisher<TResult>Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.createCollection(ClientSession clientSession, String collectionName) Create a new collection with the given name.createCollection(ClientSession clientSession, String collectionName, CreateCollectionOptions options) Create a new collection with the selected optionscreateCollection(String collectionName) Create a new collection with the given name.createCollection(String collectionName, CreateCollectionOptions options) Create a new collection with the selected optionscreateView(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.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.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.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.drop()Drops this database.drop(ClientSession clientSession) Drops this database.Get the codec registry for the MongoDatabase.getCollection(String collectionName) Gets a collection.<TDocument>
 MongoCollection<TDocument>getCollection(String collectionName, Class<TDocument> clazz) Gets a collection, with a specific default document class.getName()Gets the name of the database.Get the read concern for the MongoCollection.Get the read preference for the MongoDatabase.getTimeout(TimeUnit timeUnit) The time limit for the full execution of an operation.Get the write concern for the MongoDatabase.Gets the names of all the collections in this database.listCollectionNames(ClientSession clientSession) Gets the names of all the collections in this database.Finds all the collections in this database.listCollections(ClientSession clientSession) Finds all the collections in this database.<TResult> ListCollectionsPublisher<TResult>listCollections(ClientSession clientSession, Class<TResult> clazz) Finds all the collections in this database.<TResult> ListCollectionsPublisher<TResult>listCollections(Class<TResult> clazz) Finds all the collections in this database.runCommand(ClientSession clientSession, Bson command) Executes command in the context of the current database.runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference) Executes command in the context of the current database.<TResult> Publisher<TResult>runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, Class<TResult> clazz) Executes command in the context of the current database.<TResult> Publisher<TResult>runCommand(ClientSession clientSession, Bson command, Class<TResult> clazz) Executes command in the context of the current database.runCommand(Bson command) Executes command in the context of the current database.runCommand(Bson command, ReadPreference readPreference) Executes command in the context of the current database.<TResult> Publisher<TResult>runCommand(Bson command, ReadPreference readPreference, Class<TResult> clazz) Executes command in the context of the current database.<TResult> Publisher<TResult>runCommand(Bson command, Class<TResult> clazz) Executes command in the context of the current database.watch()Creates a change stream for this database.watch(ClientSession clientSession) Creates a change stream for this database.<TResult> ChangeStreamPublisher<TResult>watch(ClientSession clientSession, Class<TResult> resultClass) Creates a change stream for this database.watch(ClientSession clientSession, List<? extends Bson> pipeline) Creates a change stream for this database.<TResult> ChangeStreamPublisher<TResult>watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass) Creates a change stream for this database.<TResult> ChangeStreamPublisher<TResult>Creates a change stream for this database.Creates a change stream for this database.<TResult> ChangeStreamPublisher<TResult>Creates a change stream for this database.withCodecRegistry(CodecRegistry codecRegistry) Create a new MongoDatabase instance with a different codec registry.withReadConcern(ReadConcern readConcern) Create a new MongoDatabase instance with a different read concern.withReadPreference(ReadPreference readPreference) Create a new MongoDatabase instance with a different read preference.withTimeout(long timeout, TimeUnit timeUnit) Create a new MongoDatabase instance with the set time limit for the full execution of an operation.withWriteConcern(WriteConcern writeConcern) Create a new MongoDatabase instance with a different write concern.
- 
Method Details- 
getNameString getName()Gets the name of the database.- Returns:
- the database name
 
- 
getCodecRegistryCodecRegistry getCodecRegistry()Get the codec registry for the MongoDatabase.- Returns:
- the CodecRegistry
 
- 
getReadPreferenceReadPreference getReadPreference()Get the read preference for the MongoDatabase.- Returns:
- the ReadPreference
 
- 
getWriteConcernWriteConcern getWriteConcern()Get the write concern for the MongoDatabase.- Returns:
- the WriteConcern
 
- 
getReadConcernReadConcern getReadConcern()Get the read concern for the MongoCollection.- Returns:
- the ReadConcern
- Since:
- 1.2
- Since server release
- 3.2
 
- 
getTimeoutThe time limit for the full execution of an operation.If not null the following deprecated options will be ignored: waitQueueTimeoutMS,socketTimeoutMS,wTimeoutMS,maxTimeMSandmaxCommitTimeMS- nullmeans that the timeout mechanism for operations will defer to using:- waitQueueTimeoutMS: The maximum wait time in milliseconds that a thread may wait for a connection to become available
- socketTimeoutMS: How long a send or receive on a socket can take before timing out.
- wTimeoutMS: How long the server will wait for the write concern to be fulfilled before timing out.
- maxTimeMS: The cumulative time limit for processing operations on a cursor. See: cursor.maxTimeMS.
- maxCommitTimeMS: The maximum amount of time to allow a single- commitTransactioncommand to execute. See:- TransactionOptions.getMaxCommitTime(java.util.concurrent.TimeUnit).
 
- 0means infinite timeout.
- > 0The time limit to use for the full execution of an operation.
 - Parameters:
- timeUnit- the time unit
- Returns:
- the timeout in the given time unit
- Since:
- 5.2
 
- 
withCodecRegistryCreate a new MongoDatabase instance with a different codec registry.The CodecRegistryconfigured by this method is effectively treated by the driver as an instance ofCodecProvider, whichCodecRegistryextends. So there is no benefit to defining a class that implementsCodecRegistry. Rather, an application should always createCodecRegistryinstances using the factory methods inCodecRegistries.- Parameters:
- codecRegistry- the new- CodecRegistryfor the collection
- Returns:
- a new MongoDatabase instance with the different codec registry
- See Also:
 
- 
withReadPreferenceCreate a new MongoDatabase instance with a different read preference.- Parameters:
- readPreference- the new- ReadPreferencefor the collection
- Returns:
- a new MongoDatabase instance with the different readPreference
 
- 
withWriteConcernCreate a new MongoDatabase instance with a different write concern.- Parameters:
- writeConcern- the new- WriteConcernfor the collection
- Returns:
- a new MongoDatabase instance with the different writeConcern
 
- 
withReadConcernCreate a new MongoDatabase instance with a different read concern.- Parameters:
- readConcern- the new- ReadConcernfor the collection
- Returns:
- a new MongoDatabase instance with the different ReadConcern
- Since:
- 1.2
- Since server release
- 3.2
 
- 
withTimeoutCreate a new MongoDatabase instance with the set time limit for the full execution of an operation.- 0means infinite timeout.
- > 0The time limit to use for the full execution of an operation.
 - Parameters:
- timeout- the timeout, which must be greater than or equal to 0
- timeUnit- the time unit
- Returns:
- a new MongoDatabase instance with the set time limit for the full execution of an operation.
- Since:
- 5.2
- See Also:
 
- 
getCollectionGets a collection.- Parameters:
- collectionName- the name of the collection to return
- Returns:
- the collection
 
- 
getCollectionGets a collection, with a specific default document class.- Type Parameters:
- TDocument- the type of the class to use instead of- Document.
- Parameters:
- collectionName- the name of the collection to return
- clazz- the default class to cast any documents returned from the database into.
- Returns:
- the collection
 
- 
runCommandExecutes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Parameters:
- command- the command to be run
- Returns:
- a publisher containing the command result
 
- 
runCommandExecutes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Parameters:
- command- the command to be run
- readPreference- the- ReadPreferenceto be used when executing the command
- Returns:
- a publisher containing the command result
 
- 
runCommandExecutes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Type Parameters:
- TResult- the type of the class to use instead of- Document.
- Parameters:
- command- the command to be run
- clazz- the default class to cast any documents returned from the database into.
- Returns:
- a publisher containing the command result
 
- 
runCommand<TResult> Publisher<TResult> runCommand(Bson command, ReadPreference readPreference, Class<TResult> clazz) Executes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Type Parameters:
- TResult- the type of the class to use instead of- Document.
- Parameters:
- command- the command to be run
- readPreference- the- ReadPreferenceto be used when executing the command
- clazz- the default class to cast any documents returned from the database into.
- Returns:
- a publisher containing the command result
 
- 
runCommandExecutes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Parameters:
- clientSession- the client session with which to associate this operation
- command- the command to be run
- Returns:
- a publisher containing the command result
- Since:
- 1.7
- Since server release
- 3.6
 
- 
runCommandPublisher<Document> runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference) Executes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Parameters:
- clientSession- the client session with which to associate this operation
- command- the command to be run
- readPreference- the- ReadPreferenceto be used when executing the command
- Returns:
- a publisher containing the command result
- Since:
- 1.7
- Since server release
- 3.6
 
- 
runCommand<TResult> Publisher<TResult> runCommand(ClientSession clientSession, Bson command, Class<TResult> clazz) Executes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Type Parameters:
- TResult- the type of the class to use instead of- Document.
- Parameters:
- clientSession- the client session with which to associate this operation
- command- the command to be run
- clazz- the default class to cast any documents returned from the database into.
- Returns:
- a publisher containing the command result
- Since:
- 1.7
- Since server release
- 3.6
 
- 
runCommand<TResult> Publisher<TResult> runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, Class<TResult> clazz) Executes command in the context of the current database.Note: The behavior of runCommandis undefined if the provided command document includes amaxTimeMSfield and thetimeoutMSsetting has been set.- Type Parameters:
- TResult- the type of the class to use instead of- Document.
- Parameters:
- clientSession- the client session with which to associate this operation
- command- the command to be run
- readPreference- the- ReadPreferenceto be used when executing the command
- clazz- the default class to cast any documents returned from the database into.
- Returns:
- a publisher containing the command result
- Since:
- 1.7
- Since server release
- 3.6
 
- 
dropDrops this database.- Returns:
- a publisher identifying when the database has been dropped
- MongoDB documentation
- Drop database
 
- 
dropDrops this database.- Parameters:
- clientSession- the client session with which to associate this operation
- Returns:
- a publisher identifying when the database has been dropped
- Since:
- 1.7
- MongoDB documentation
- Drop database
- Since server release
- 3.6
 
- 
listCollectionNamesListCollectionNamesPublisher listCollectionNames()Gets the names of all the collections in this database.- Returns:
- a publisher with all the names of all the collections in this database
- MongoDB documentation
- listCollections
 
- 
listCollectionNamesGets the names of all the collections in this database.- Parameters:
- clientSession- the client session with which to associate this operation
- Returns:
- a publisher with all the names of all the collections in this database
- Since:
- 1.7
- MongoDB documentation
- listCollections
- Since server release
- 3.6
 
- 
listCollectionsListCollectionsPublisher<Document> listCollections()Finds all the collections in this database.- Returns:
- the fluent list collections interface
- MongoDB documentation
- listCollections
 
- 
listCollectionsFinds all the collections in this database.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- clazz- the class to decode each document into
- Returns:
- the fluent list collections interface
- MongoDB documentation
- listCollections
 
- 
listCollectionsFinds all the collections in this database.- Parameters:
- clientSession- the client session with which to associate this operation
- Returns:
- the fluent list collections interface
- Since:
- 1.7
- MongoDB documentation
- listCollections
- Since server release
- 3.6
 
- 
listCollections<TResult> ListCollectionsPublisher<TResult> listCollections(ClientSession clientSession, Class<TResult> clazz) Finds all the collections in this database.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- clientSession- the client session with which to associate this operation
- clazz- the class to decode each document into
- Returns:
- the fluent list collections interface
- Since:
- 1.7
- MongoDB documentation
- listCollections
- Since server release
- 3.6
 
- 
createCollectionCreate a new collection with the given name.- Parameters:
- collectionName- the name for the new collection to create
- Returns:
- a publisher identifying when the collection has been created
- MongoDB documentation
- Create Command
 
- 
createCollectionCreate a new collection with the selected options- Parameters:
- collectionName- the name for the new collection to create
- options- various options for creating the collection
- Returns:
- a publisher identifying when the collection has been created
- MongoDB documentation
- Create Command
 
- 
createCollectionCreate a new collection with the given name.- Parameters:
- clientSession- the client session with which to associate this operation
- collectionName- the name for the new collection to create
- Returns:
- a publisher identifying when the collection has been created
- Since:
- 1.7
- MongoDB documentation
- Create Command
- Since server release
- 3.6
 
- 
createCollectionPublisher<Void> createCollection(ClientSession clientSession, String collectionName, CreateCollectionOptions options) Create a new collection with the selected options- Parameters:
- clientSession- the client session with which to associate this operation
- collectionName- the name for the new collection to create
- options- various options for creating the collection
- Returns:
- a publisher identifying when the collection has been created
- Since:
- 1.7
- MongoDB documentation
- Create Command
- Since server release
- 3.6
 
- 
createViewCreates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.- Parameters:
- viewName- the name of the view to create
- viewOn- the backing collection/view for the view
- pipeline- the pipeline that defines the view
- Returns:
- an observable identifying when the collection view has been created
- Since:
- 1.3
- MongoDB documentation
- Create Command
- Since server release
- 3.4
 
- 
createViewPublisher<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.- Parameters:
- viewName- the name of the view to create
- viewOn- the backing collection/view for the view
- pipeline- the pipeline that defines the view
- createViewOptions- various options for creating the view
- Returns:
- an observable identifying when the collection view has been created
- Since:
- 1.3
- MongoDB documentation
- Create Command
- Since server release
- 3.4
 
- 
createViewPublisher<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.- Parameters:
- clientSession- the client session with which to associate this operation
- viewName- the name of the view to create
- viewOn- the backing collection/view for the view
- pipeline- the pipeline that defines the view
- Returns:
- an observable identifying when the collection view has been created
- Since:
- 1.7
- MongoDB documentation
- Create Command
- Since server release
- 3.6
 
- 
createViewPublisher<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.- Parameters:
- clientSession- the client session with which to associate this operation
- viewName- the name of the view to create
- viewOn- the backing collection/view for the view
- pipeline- the pipeline that defines the view
- createViewOptions- various options for creating the view
- Returns:
- an observable identifying when the collection view has been created
- Since:
- 1.7
- MongoDB documentation
- Create Command
- Since server release
- 3.6
 
- 
watchChangeStreamPublisher<Document> watch()Creates a change stream for this database.- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watchCreates a change stream for this database.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- resultClass- the class to decode each document into
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watchCreates a change stream for this database.- Parameters:
- pipeline- the aggregation pipeline to apply to the change stream.
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watch<TResult> ChangeStreamPublisher<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass) Creates a change stream for this database.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- pipeline- the aggregation pipeline to apply to the change stream
- resultClass- the class to decode each document into
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watchCreates a change stream for this database.- Parameters:
- clientSession- the client session with which to associate this operation
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watch<TResult> ChangeStreamPublisher<TResult> watch(ClientSession clientSession, Class<TResult> resultClass) Creates a change stream for this database.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- clientSession- the client session with which to associate this operation
- resultClass- the class to decode each document into
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watchCreates a change stream for this database.- Parameters:
- clientSession- the client session with which to associate this operation
- pipeline- the aggregation pipeline to apply to the change stream.
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
watch<TResult> ChangeStreamPublisher<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass) Creates a change stream for this database.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- clientSession- the client session with which to associate this operation
- pipeline- the aggregation pipeline to apply to the change stream
- resultClass- the class to decode each document into
- Returns:
- the change stream iterable
- Since:
- 1.9
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
 
- 
aggregateRuns an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.- Parameters:
- pipeline- the aggregation pipeline
- Returns:
- an iterable containing the result of the aggregation operation
- Since:
- 1.11
- MongoDB documentation
- Aggregate Command
- Since server release
- 3.6
 
- 
aggregate<TResult> AggregatePublisher<TResult> aggregate(List<? extends Bson> pipeline, Class<TResult> resultClass) Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- pipeline- the aggregation pipeline
- resultClass- the class to decode each document into
- Returns:
- an iterable containing the result of the aggregation operation
- Since:
- 1.11
- MongoDB documentation
- Aggregate Command
- Since server release
- 3.6
 
- 
aggregateRuns an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.- Parameters:
- clientSession- the client session with which to associate this operation
- pipeline- the aggregation pipeline
- Returns:
- an iterable containing the result of the aggregation operation
- Since:
- 1.11
- MongoDB documentation
- Aggregate Command
- Since server release
- 3.6
 
- 
aggregate<TResult> AggregatePublisher<TResult> aggregate(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass) Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as$currentOpand$listLocalSessions.- Type Parameters:
- TResult- the target document type of the iterable.
- Parameters:
- clientSession- the client session with which to associate this operation
- pipeline- the aggregation pipeline
- resultClass- the class to decode each document into
- Returns:
- an iterable containing the result of the aggregation operation
- Since:
- 1.11
- MongoDB documentation
- Aggregate Command
- Since server release
- 3.6
 
 
-