public class MongoFactory extends Object
WriteConcern.REPLICAS_SAFE
when
more than one address is provided, or WriteConcern.FSYNC_SAFE
when only one server is available. The idea of
these defaults is that data must be able to survive a (not too heavy) crash without loss of data. We wouldn't want to
publish untraceable events, would we...Constructor and Description |
---|
MongoFactory() |
Modifier and Type | Method and Description |
---|---|
com.mongodb.MongoClient |
createMongo()
Creates a mongo instance based on the provided configuration.
|
void |
setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
Provide a list of ServerAddress objects to use for locating the Mongo replica set.
|
void |
setMongoOptions(com.mongodb.MongoClientOptions mongoOptions)
Provide an instance of MongoOptions to be used for the connections.
|
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Provided a write concern to be used by the mongo instance.
|
public com.mongodb.MongoClient createMongo()
public void setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
127.0.0.1
) and port
(com.mongodb.ServerAddress#defaultPort
)
Defaults to an empty list, which locates a single Mongo instance on the default host (127.0.0.1
)
and port (com.mongodb.ServerAddress#defaultPort
)
mongoAddresses
- List of ServerAddress instancespublic void setMongoOptions(com.mongodb.MongoClientOptions mongoOptions)
mongoOptions
- MongoOptions to overrule the defaultpublic void setWriteConcern(com.mongodb.WriteConcern writeConcern)
setMongoAddresses(java.util.List)
. For example, providing
WriteConcern.REPLICAS_SAFE
in combination with a single address will cause each write operation to hang.
While safe (e.g. WriteConcern.REPLICAS_SAFE
) WriteConcerns allow you to detect concurrency issues
immediately, you might want to use a more relaxed write concern if you have other mechanisms in place to ensure
consistency.
Defaults to WriteConcern.REPLICAS_SAFE
if you provided more than one address with
setMongoAddresses(java.util.List)
, or WriteConcern.FSYNC_SAFE
if there is only one address (or
none at all).writeConcern
- WriteConcern to use for the connectionsCopyright © 2010–2017. All rights reserved.