public class SimpleMongoDbFactory extends Object implements org.springframework.beans.factory.DisposableBean, MongoDbFactory
DB instances from a MongoClient instance.| Constructor and Description |
|---|
SimpleMongoDbFactory(com.mongodb.MongoClient mongoClient,
String databaseName)
Creates a new
SimpleMongoDbFactory instance from the given MongoClient. |
SimpleMongoDbFactory(com.mongodb.MongoClientURI uri)
Creates a new
SimpleMongoDbFactory instance from the given MongoClientURI. |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Clean up the Mongo instance if it was created by the factory itself.
|
com.mongodb.client.MongoDatabase |
getDb()
Creates a default
DB instance. |
com.mongodb.client.MongoDatabase |
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. |
com.mongodb.DB |
getLegacyDb() |
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Configures the
WriteConcern to be used on the DB instance being created. |
public SimpleMongoDbFactory(com.mongodb.MongoClientURI uri)
SimpleMongoDbFactory instance from the given MongoClientURI.uri - must not be null.UnknownHostExceptionpublic SimpleMongoDbFactory(com.mongodb.MongoClient mongoClient,
String databaseName)
SimpleMongoDbFactory instance from the given MongoClient.mongoClient - must not be null.databaseName - must not be null.public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
WriteConcern to be used on the DB instance being created.writeConcern - the writeConcern to setpublic com.mongodb.client.MongoDatabase getDb()
throws org.springframework.dao.DataAccessException
MongoDbFactoryDB instance.getDb in interface MongoDbFactoryorg.springframework.dao.DataAccessExceptionpublic com.mongodb.client.MongoDatabase 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 MongoDbFactorypublic com.mongodb.DB getLegacyDb()
getLegacyDb in interface MongoDbFactoryCopyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.