Module spring.data.mongodb
Class SimpleReactiveMongoDatabaseFactory
java.lang.Object
org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory
- All Implemented Interfaces:
DisposableBean,CodecRegistryProvider,ReactiveMongoDatabaseFactory
public class SimpleReactiveMongoDatabaseFactory
extends Object
implements DisposableBean, ReactiveMongoDatabaseFactory
Factory to create
MongoDatabase instances from a MongoClient instance.- Since:
- 2.0
- Author:
- Mark Paluch, Christoph Strobl, Mathieu Ouellet
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleReactiveMongoDatabaseFactory(com.mongodb.ConnectionString connectionString) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenConnectionString.SimpleReactiveMongoDatabaseFactory(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenMongoClient. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Clean up the Mongo instance if it was created by the factory itself.org.bson.codecs.configuration.CodecRegistryGet the underlyingCodecRegistryused by the reactive MongoDB Java driver.Exposes a sharedMongoExceptionTranslator.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase>Creates a defaultMongoDatabaseinstance.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase>getMongoDatabase(String dbName) Obtain aMongoDatabaseinstance to access the database with the given name.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.ClientSession>getSession(com.mongodb.ClientSessionOptions options) Obtain aMonoemitting aClientSessionfor givenoptions.voidsetWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcernto be used on theMongoDatabaseinstance being created.withSession(com.mongodb.reactivestreams.client.ClientSession session) Obtain aClientSessionbound instance ofReactiveMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider
getCodecFor, hasCodecForMethods inherited from interface org.springframework.data.mongodb.ReactiveMongoDatabaseFactory
isTransactionActive
-
Constructor Details
-
SimpleReactiveMongoDatabaseFactory
public SimpleReactiveMongoDatabaseFactory(com.mongodb.ConnectionString connectionString) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenConnectionString.- Parameters:
connectionString- must not be null.
-
SimpleReactiveMongoDatabaseFactory
public SimpleReactiveMongoDatabaseFactory(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenMongoClient.- Parameters:
mongoClient- must not be null.databaseName- must not be null.- Since:
- 1.7
-
-
Method Details
-
setWriteConcern
public void setWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcernto be used on theMongoDatabaseinstance being created.- Parameters:
writeConcern- the writeConcern to set
-
getMongoDatabase
public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase() throws DataAccessExceptionDescription copied from interface:ReactiveMongoDatabaseFactoryCreates a defaultMongoDatabaseinstance.- Specified by:
getMongoDatabasein interfaceReactiveMongoDatabaseFactory- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase(String dbName) throws DataAccessException Description copied from interface:ReactiveMongoDatabaseFactoryObtain aMongoDatabaseinstance to access the database with the given name.- Specified by:
getMongoDatabasein interfaceReactiveMongoDatabaseFactory- Parameters:
dbName- must not be null or empty.- Returns:
- never null.
- Throws:
DataAccessException
-
destroy
Clean up the Mongo instance if it was created by the factory itself.- Specified by:
destroyin interfaceDisposableBean- Throws:
Exception- See Also:
-
getExceptionTranslator
Description copied from interface:ReactiveMongoDatabaseFactoryExposes a sharedMongoExceptionTranslator.- Specified by:
getExceptionTranslatorin interfaceReactiveMongoDatabaseFactory- Returns:
- will never be null.
-
getCodecRegistry
public org.bson.codecs.configuration.CodecRegistry getCodecRegistry()Description copied from interface:ReactiveMongoDatabaseFactoryGet the underlyingCodecRegistryused by the reactive MongoDB Java driver.- Specified by:
getCodecRegistryin interfaceCodecRegistryProvider- Specified by:
getCodecRegistryin interfaceReactiveMongoDatabaseFactory- Returns:
- never null.
-
getSession
public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.ClientSession> getSession(com.mongodb.ClientSessionOptions options) Description copied from interface:ReactiveMongoDatabaseFactoryObtain aMonoemitting aClientSessionfor givenoptions.- Specified by:
getSessionin interfaceReactiveMongoDatabaseFactory- Parameters:
options- must not be null.- Returns:
- never null.
-
withSession
public ReactiveMongoDatabaseFactory withSession(com.mongodb.reactivestreams.client.ClientSession session) Description copied from interface:ReactiveMongoDatabaseFactoryObtain aClientSessionbound instance ofReactiveMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.- Specified by:
withSessionin interfaceReactiveMongoDatabaseFactory- Parameters:
session- must not be null.- Returns:
- never null.
-