public class SimpleMongoDbFactory extends Object implements org.springframework.beans.factory.DisposableBean, MongoDbFactory
DB instances from a Mongo instance.| Constructor and Description |
|---|
SimpleMongoDbFactory(com.mongodb.Mongo mongo,
String databaseName)
Create an instance of
SimpleMongoDbFactory given the Mongo instance and database name. |
SimpleMongoDbFactory(com.mongodb.Mongo mongo,
String databaseName,
org.springframework.data.authentication.UserCredentials credentials)
Create an instance of SimpleMongoDbFactory given the Mongo instance, database name, and username/password
|
SimpleMongoDbFactory(com.mongodb.Mongo mongo,
String databaseName,
org.springframework.data.authentication.UserCredentials credentials,
String authenticationDatabaseName)
Create an instance of SimpleMongoDbFactory given the Mongo instance, database name, and username/password
|
SimpleMongoDbFactory(com.mongodb.MongoURI uri)
Creates a new
SimpleMongoDbFactory instance from the given MongoURI. |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Clean up the Mongo instance if it was created by the factory itself.
|
com.mongodb.DB |
getDb()
Creates a default
DB instance. |
com.mongodb.DB |
getDb(String dbName)
Creates a
DB instance to access the database with the given name. |
org.springframework.dao.support.PersistenceExceptionTranslator |
getExceptionTranslator()
Exposes a shared
MongoExceptionTranslator. |
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Configures the
WriteConcern to be used on the DB instance being created. |
public SimpleMongoDbFactory(com.mongodb.Mongo mongo,
String databaseName)
SimpleMongoDbFactory given the Mongo instance and database name.mongo - Mongo instance, must not be null.databaseName - database name, not be null or empty.public SimpleMongoDbFactory(com.mongodb.Mongo mongo,
String databaseName,
org.springframework.data.authentication.UserCredentials credentials)
mongo - Mongo instance, must not be null.databaseName - Database name, must not be null or empty.credentials - username and password.public SimpleMongoDbFactory(com.mongodb.Mongo mongo,
String databaseName,
org.springframework.data.authentication.UserCredentials credentials,
String authenticationDatabaseName)
mongo - Mongo instance, must not be null.databaseName - Database name, must not be null or empty.credentials - username and password.authenticationDatabaseName - the database name to use for authenticationpublic SimpleMongoDbFactory(com.mongodb.MongoURI uri)
throws com.mongodb.MongoException,
UnknownHostException
SimpleMongoDbFactory instance from the given MongoURI.uri - must not be null.com.mongodb.MongoExceptionUnknownHostExceptionMongoURIpublic void setWriteConcern(com.mongodb.WriteConcern writeConcern)
WriteConcern to be used on the DB instance being created.writeConcern - the writeConcern to setpublic com.mongodb.DB getDb()
throws org.springframework.dao.DataAccessException
MongoDbFactoryDB instance.getDb in interface MongoDbFactoryorg.springframework.dao.DataAccessExceptionpublic com.mongodb.DB getDb(String dbName) throws org.springframework.dao.DataAccessException
MongoDbFactoryDB instance to access the database with the given name.getDb in interface MongoDbFactorydbName - must not be null or empty.org.springframework.dao.DataAccessExceptionpublic void destroy()
throws Exception
destroy in interface org.springframework.beans.factory.DisposableBeanExceptionDisposableBean.destroy()public org.springframework.dao.support.PersistenceExceptionTranslator getExceptionTranslator()
MongoDbFactoryMongoExceptionTranslator.getExceptionTranslator in interface MongoDbFactoryCopyright © 2021. All rights reserved.