public class SimpleMongoDbFactory extends Object implements DisposableBean, MongoDbFactory
Constructor and Description |
---|
SimpleMongoDbFactory(Mongo mongo,
String databaseName)
Create an instance of
SimpleMongoDbFactory given the Mongo instance and database name. |
SimpleMongoDbFactory(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(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.
|
DB |
getDb()
Creates a default
DB instance. |
DB |
getDb(String dbName)
Creates a
DB instance to access the database with the given name. |
void |
setWriteConcern(WriteConcern writeConcern)
Configures the
WriteConcern to be used on the DB instance being created. |
public SimpleMongoDbFactory(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.public SimpleMongoDbFactory(Mongo mongo, String databaseName, org.springframework.data.authentication.UserCredentials credentials)
mongo
- Mongo instance, must not be null.databaseName
- Database name, must not be null.credentials
- username and password.public SimpleMongoDbFactory(MongoURI uri) throws MongoException, UnknownHostException
SimpleMongoDbFactory
instance from the given MongoURI
.uri
- must not be null.MongoException
UnknownHostException
MongoURI
public void setWriteConcern(WriteConcern writeConcern)
WriteConcern
to be used on the DB
instance being created.writeConcern
- the writeConcern to setpublic DB getDb() throws DataAccessException
MongoDbFactory
DB
instance.getDb
in interface MongoDbFactory
DataAccessException
public DB getDb(String dbName) throws DataAccessException
MongoDbFactory
DB
instance to access the database with the given name.getDb
in interface MongoDbFactory
dbName
- must not be null or empty.DataAccessException
public void destroy() throws Exception
destroy
in interface DisposableBean
Exception
DisposableBean.destroy()
Copyright © 2012. All Rights Reserved.