com.mongodb
Class WriteConcern

java.lang.Object
  extended by com.mongodb.WriteConcern

public class WriteConcern
extends java.lang.Object

WriteConcern control the write behavior for with various options, as well as exception raising on error conditions.

w

wtimeout how long to wait for slaves before failing

fsync force fsync to disk


MongoDB Doc Links

Field Summary
static WriteConcern FSYNC_SAFE
          Exceptions are raised for network issues, and server errors and the write operation waits for the server to flush the data to disk
static WriteConcern NONE
          No exceptions are raised, even for network issues
static WriteConcern NORMAL
          Exceptions are raised for network issues, but not server errors
static WriteConcern REPLICAS_SAFE
          Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation
static WriteConcern SAFE
          Exceptions are raised for network issues, and server errors; waits on a server for the write operation
static WriteConcern STRICT
          Deprecated. 
 
Constructor Summary
WriteConcern()
           
WriteConcern(boolean fsync)
           
WriteConcern(int w)
          Specifies the number of servers to wait for on the write operation, and exception raising behavior
WriteConcern(int w, int wtimeout)
          Specifies the number of servers to wait for on the write operation, and the amount of time (ms) to wait.
WriteConcern(int w, int wtimeout, boolean fsync)
          Specifies the number of servers to wait for on the write operation, and the amount of time (ms) to wait.
 
Method Summary
 boolean callGetLastError()
           
 boolean fsync()
           
 BasicDBObject getCommand()
           
 int getW()
           
 int getWtimeout()
           
 boolean raiseNetworkErrors()
           
 java.lang.String toString()
           
static WriteConcern valueOf(java.lang.String name)
          Get the WriteConcern constants by name: NONE, NORMAL, SAFE, FSYNC_SAFE, REPLICA_SAFE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONE

public static final WriteConcern NONE
No exceptions are raised, even for network issues


NORMAL

public static final WriteConcern NORMAL
Exceptions are raised for network issues, but not server errors


SAFE

public static final WriteConcern SAFE
Exceptions are raised for network issues, and server errors; waits on a server for the write operation


STRICT

@Deprecated
public static final WriteConcern STRICT
Deprecated. 

FSYNC_SAFE

public static final WriteConcern FSYNC_SAFE
Exceptions are raised for network issues, and server errors and the write operation waits for the server to flush the data to disk


REPLICAS_SAFE

public static final WriteConcern REPLICAS_SAFE
Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation

Constructor Detail

WriteConcern

public WriteConcern()

WriteConcern

public WriteConcern(int w)

Specifies the number of servers to wait for on the write operation, and exception raising behavior

w represents # of servers:


WriteConcern

public WriteConcern(int w,
                    int wtimeout)

Specifies the number of servers to wait for on the write operation, and the amount of time (ms) to wait.

Note: w should be > 1


WriteConcern

public WriteConcern(boolean fsync)

WriteConcern

public WriteConcern(int w,
                    int wtimeout,
                    boolean fsync)

Specifies the number of servers to wait for on the write operation, and the amount of time (ms) to wait.

Note: w should be > 1

Method Detail

valueOf

public static WriteConcern valueOf(java.lang.String name)
Get the WriteConcern constants by name: NONE, NORMAL, SAFE, FSYNC_SAFE, REPLICA_SAFE. (matching is done case insensitively)


getCommand

public BasicDBObject getCommand()

getW

public int getW()
Returns:
the number of servers to write to

getWtimeout

public int getWtimeout()
Returns:
the write timeout (in milliseconds)

fsync

public boolean fsync()
Returns:
If files are sync'd to disk.

raiseNetworkErrors

public boolean raiseNetworkErrors()

callGetLastError

public boolean callGetLastError()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object