public class

MongoOptions

extends Object
java.lang.Object
   ↳ com.mongodb.MongoOptions

Class Overview

Various settings for the driver. Not thread safe.

Summary

Fields
public boolean autoConnectRetry If true, the driver will keep trying to connect to the same server in case that the socket cannot be established.
public int connectTimeout The connection timeout in milliseconds.
public int connectionsPerHost The maximum number of connections allowed per host for this Mongo instance.
public DBDecoderFactory dbDecoderFactory Override the DBCallback factory.
public DBEncoderFactory dbEncoderFactory Override the encoding factory.
public String description

The description for Mongo instances created with these options.

public boolean fsync The "fsync" value of the global WriteConcern.
public boolean j The "j" value of the global WriteConcern.
public long maxAutoConnectRetryTime The maximum amount of time in MS to spend retrying to open connection to the same server.
public int maxWaitTime The maximum wait time in milliseconds that a thread may wait for a connection to become available.
public boolean safe If true the driver will use a WriteConcern of WriteConcern.SAFE for all operations.
public boolean slaveOk This field is deprecated. Replaced in MongoDB 2.0/Java Driver 2.7 with ReadPreference.SECONDARY
public SocketFactory socketFactory sets the socket factory for creating sockets to mongod Default is SocketFactory.getDefault()
public boolean socketKeepAlive This flag controls the socket keep alive feature that keeps a connection alive through firewalls setKeepAlive(boolean) Default is false.
public int socketTimeout The socket timeout in milliseconds It is used for I/O socket read and write operations setSoTimeout(int) Default is 0 and means no timeout.
public int threadsAllowedToBlockForConnectionMultiplier this multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool.
public int w The "w" value, (number of writes), of the global WriteConcern.
public int wtimeout The "wtimeout" value of the global WriteConcern.
Public Constructors
MongoOptions()
Public Methods
MongoOptions copy()
synchronized int getConnectTimeout()
synchronized int getConnectionsPerHost()
synchronized DBDecoderFactory getDbDecoderFactory()
synchronized DBEncoderFactory getDbEncoderFactory()
synchronized String getDescription()
synchronized long getMaxAutoConnectRetryTime()
synchronized int getMaxWaitTime()
synchronized SocketFactory getSocketFactory()
synchronized int getSocketTimeout()
synchronized int getThreadsAllowedToBlockForConnectionMultiplier()
synchronized int getW()
WriteConcern getWriteConcern()
Helper method to return the appropriate WriteConcern instance based on the current related options settings.
synchronized int getWtimeout()
synchronized boolean isAutoConnectRetry()
synchronized boolean isFsync()
synchronized boolean isJ()
synchronized boolean isSafe()
synchronized boolean isSocketKeepAlive()
void reset()
synchronized void setAutoConnectRetry(boolean retry)
synchronized void setConnectTimeout(int timeoutMS)
synchronized void setConnectionsPerHost(int connections)
synchronized void setDbDecoderFactory(DBDecoderFactory factory)
synchronized void setDbEncoderFactory(DBEncoderFactory factory)
synchronized void setDescription(String desc)
synchronized void setFsync(boolean sync)
synchronized void setJ(boolean safe)
synchronized void setMaxAutoConnectRetryTime(long retryTimeMS)
synchronized void setMaxWaitTime(int timeMS)
synchronized void setSafe(boolean isSafe)
synchronized void setSocketFactory(SocketFactory factory)
synchronized void setSocketKeepAlive(boolean keepAlive)
synchronized void setSocketTimeout(int timeoutMS)
synchronized void setThreadsAllowedToBlockForConnectionMultiplier(int threads)
synchronized void setW(int val)
synchronized void setWtimeout(int timeoutMS)
String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public boolean autoConnectRetry

If true, the driver will keep trying to connect to the same server in case that the socket cannot be established. There is maximum amount of time to keep retrying, which is 15s by default. This can be useful to avoid some exceptions being thrown when a server is down temporarily by blocking the operations. It also can be useful to smooth the transition to a new master (so that a new master is elected within the retry time). Note that when using this flag: - for a replica set, the driver will trying to connect to the old master for that time, instead of failing over to the new one right away - this does not prevent exception from being thrown in read/write operations on the socket, which must be handled by application Even if this flag is false, the driver already has mechanisms to automatically recreate broken connections and retry the read operations. Default is false.

public int connectTimeout

The connection timeout in milliseconds. It is used solely when establishing a new connection connect(java.net.SocketAddress, int) Default is 0 and means no timeout.

public int connectionsPerHost

The maximum number of connections allowed per host for this Mongo instance. Those connections will be kept in a pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection. Default is 10.

See Also
  • {@linkplain MongoOptions#threadsAllowedToBlockForConnectionMultiplier}

public DBDecoderFactory dbDecoderFactory

Override the DBCallback factory. Default is for the standard Mongo Java driver configuration.

public DBEncoderFactory dbEncoderFactory

Override the encoding factory. Default is for the standard Mongo Java driver configuration.

public String description

The description for Mongo instances created with these options. This is used in various places like logging.

public boolean fsync

The "fsync" value of the global WriteConcern. true indicates writes should wait for data to be written to server data file Default is false.

public boolean j

The "j" value of the global WriteConcern. true indicates writes should wait for a journaling group commit Default is false.

public long maxAutoConnectRetryTime

The maximum amount of time in MS to spend retrying to open connection to the same server. Default is 0, which means to use the default 15s if autoConnectRetry is on.

public int maxWaitTime

The maximum wait time in milliseconds that a thread may wait for a connection to become available. Default is 120,000. A value of 0 means that it will not wait. A negative value means to wait indefinitely.

public boolean safe

If true the driver will use a WriteConcern of WriteConcern.SAFE for all operations. If w, wtimeout, fsync or j are specified, this setting is ignored. Default is false.

public boolean slaveOk

This field is deprecated.
Replaced in MongoDB 2.0/Java Driver 2.7 with ReadPreference.SECONDARY

This flag specifies if the driver is allowed to read from secondary (slave) servers. Specifically in the current implementation, the driver will avoid reading from the primary server and round robin requests to secondaries. Driver also factors in the latency to secondaries when choosing a server. Note that reading from secondaries can increase performance and reliability, but it may result in temporary inconsistent results. Default is false.

See Also
  • com.mongodb.ReadPreference.SECONDARY

public SocketFactory socketFactory

sets the socket factory for creating sockets to mongod Default is SocketFactory.getDefault()

public boolean socketKeepAlive

This flag controls the socket keep alive feature that keeps a connection alive through firewalls setKeepAlive(boolean) Default is false.

public int socketTimeout

The socket timeout in milliseconds It is used for I/O socket read and write operations setSoTimeout(int) Default is 0 and means no timeout.

public int threadsAllowedToBlockForConnectionMultiplier

this multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool. All further threads will get an exception right away. For example if connectionsPerHost is 10 and threadsAllowedToBlockForConnectionMultiplier is 5, then up to 50 threads can wait for a connection. Default is 5.

public int w

The "w" value, (number of writes), of the global WriteConcern. Default is 0.

public int wtimeout

The "wtimeout" value of the global WriteConcern. Default is 0.

Public Constructors

public MongoOptions ()

Public Methods

public MongoOptions copy ()

public synchronized int getConnectTimeout ()

Returns
  • the connection timeout in milliseconds.

public synchronized int getConnectionsPerHost ()

Returns
  • the maximum number of connections allowed per host for this Mongo instance

public synchronized DBDecoderFactory getDbDecoderFactory ()

Returns
  • the DBCallback decoding factory

public synchronized DBEncoderFactory getDbEncoderFactory ()

Returns
  • the encoding factory

public synchronized String getDescription ()

Returns
  • The description for Mongo instances created with these options

public synchronized long getMaxAutoConnectRetryTime ()

Returns
  • max time in MS to retrying open connection

public synchronized int getMaxWaitTime ()

Returns
  • The maximum time in milliseconds that threads wait for a connection

public synchronized SocketFactory getSocketFactory ()

Returns
  • the socket factory for creating sockets to mongod

public synchronized int getSocketTimeout ()

Returns
  • The socket timeout in milliseconds

public synchronized int getThreadsAllowedToBlockForConnectionMultiplier ()

Returns
  • the maximum number of threads that may be waiting for a connection

public synchronized int getW ()

Returns
  • value returns the number of writes of the global WriteConcern.

public WriteConcern getWriteConcern ()

Helper method to return the appropriate WriteConcern instance based on the current related options settings.

public synchronized int getWtimeout ()

Returns
  • timeout for write operation

public synchronized boolean isAutoConnectRetry ()

Returns
  • keep trying connection flag

public synchronized boolean isFsync ()

Returns
  • true if global write concern is set to fsync

public synchronized boolean isJ ()

Returns
  • true if global write concern is set to journal safe

public synchronized boolean isSafe ()

Returns
  • true if driver uses WriteConcern.SAFE for all operations.

public synchronized boolean isSocketKeepAlive ()

Returns
  • connection keep-alive flag

public void reset ()

public synchronized void setAutoConnectRetry (boolean retry)

Parameters
retry sets keep trying connection flag

public synchronized void setConnectTimeout (int timeoutMS)

Parameters
timeoutMS set the connection timeout in milliseconds.

public synchronized void setConnectionsPerHost (int connections)

Parameters
connections sets the maximum number of connections allowed per host for this Mongo instance

public synchronized void setDbDecoderFactory (DBDecoderFactory factory)

Parameters
factory sets the DBCallback decoding factory

public synchronized void setDbEncoderFactory (DBEncoderFactory factory)

Parameters
factory sets the encoding factory

public synchronized void setDescription (String desc)

Parameters
desc The description for Mongo instances created with these options

public synchronized void setFsync (boolean sync)

Parameters
sync sets global write concern's fsync safe value

public synchronized void setJ (boolean safe)

Parameters
safe sets global write concern's journal safe value

public synchronized void setMaxAutoConnectRetryTime (long retryTimeMS)

Parameters
retryTimeMS set max time in MS to retrying open connection

public synchronized void setMaxWaitTime (int timeMS)

Parameters
timeMS set the maximum time in milliseconds that threads wait for a connection

public synchronized void setSafe (boolean isSafe)

Parameters
isSafe true if driver uses WriteConcern.SAFE for all operations.

public synchronized void setSocketFactory (SocketFactory factory)

Parameters
factory sets the socket factory for creating sockets to mongod

public synchronized void setSocketKeepAlive (boolean keepAlive)

Parameters
keepAlive set connection keep-alive flag

public synchronized void setSocketTimeout (int timeoutMS)

Parameters
timeoutMS set the socket timeout in milliseconds

public synchronized void setThreadsAllowedToBlockForConnectionMultiplier (int threads)

public synchronized void setW (int val)

Parameters
val set the number of writes of the global WriteConcern.

public synchronized void setWtimeout (int timeoutMS)

Parameters
timeoutMS sets timeout for write operation

public String toString ()