com.mongodb
Class ReadPreference

java.lang.Object
  extended by com.mongodb.ReadPreference
Direct Known Subclasses:
ReadPreference.TaggedReadPreference, TaggableReadPreference

public abstract class ReadPreference
extends Object

An abstract class that represents preferred replica set members to which a query or command can be sent.


MongoDB Doc Links

Nested Class Summary
static class ReadPreference.TaggedReadPreference
          Deprecated. As of release 2.9, replaced by ReadPreference.secondaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)
 
Field Summary
static ReadPreference PRIMARY
          Deprecated. As of release 2.9.0, replaced by ReadPreference.primary()
static ReadPreference SECONDARY
          Deprecated. As of release 2.9.0, replaced by ReadPreference.secondaryPreferred()
 
Method Summary
abstract  String getName()
          The name of this read preference.
abstract  boolean isSlaveOk()
           
static ReadPreference nearest()
           
static TaggableReadPreference nearest(DBObject firstTagSet, DBObject... remainingTagSets)
           
static ReadPreference primary()
           
static ReadPreference primaryPreferred()
           
static TaggableReadPreference primaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)
           
static ReadPreference secondary()
           
static TaggableReadPreference secondary(DBObject firstTagSet, DBObject... remainingTagSets)
           
static ReadPreference secondaryPreferred()
           
static TaggableReadPreference secondaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)
           
abstract  DBObject toDBObject()
           
static ReadPreference valueOf(String name)
           
static TaggableReadPreference valueOf(String name, DBObject firstTagSet, DBObject... remainingTagSets)
           
static ReadPreference withTags(DBObject tags)
          Deprecated. As of release 2.9.0, replaced by ReadPreference.secondaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)
static ReadPreference withTags(Map<String,String> tags)
          Deprecated. As of release 2.9.0, replaced by ReadPreference.secondaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIMARY

@Deprecated
public static final ReadPreference PRIMARY
Deprecated. As of release 2.9.0, replaced by ReadPreference.primary()
A primary read preference. Equivalent to calling ReadPreference.primary().

See Also:
primary()

SECONDARY

@Deprecated
public static final ReadPreference SECONDARY
Deprecated. As of release 2.9.0, replaced by ReadPreference.secondaryPreferred()
A secondary-preferred read preference. Equivalent to calling ReadPreference.secondaryPreferred. This reference should really have been called ReadPreference.SECONDARY_PREFERRED, but the naming of it preceded the idea of distinguishing between secondary and secondary-preferred, so for backwards compatibility, leaving the name as is with the behavior as it was when it was created.

See Also:
secondary(), secondaryPreferred()
Method Detail

isSlaveOk

public abstract boolean isSlaveOk()
Returns:
true if this preference allows reads or commands from secondary nodes

toDBObject

public abstract DBObject toDBObject()
Returns:
DBObject representation of this preference

getName

public abstract String getName()
The name of this read preference.

Returns:
the name

primary

public static ReadPreference primary()
Returns:
ReadPreference which reads from primary only

primaryPreferred

public static ReadPreference primaryPreferred()
Returns:
ReadPreference which reads primary if available.

primaryPreferred

public static TaggableReadPreference primaryPreferred(DBObject firstTagSet,
                                                      DBObject... remainingTagSets)
Returns:
ReadPreference which reads primary if available, otherwise a secondary respective of tags.

secondary

public static ReadPreference secondary()
Returns:
ReadPreference which reads secondary.

secondary

public static TaggableReadPreference secondary(DBObject firstTagSet,
                                               DBObject... remainingTagSets)
Returns:
ReadPreference which reads secondary respective of tags.

secondaryPreferred

public static ReadPreference secondaryPreferred()
Returns:
ReadPreference which reads secondary if available, otherwise from primary.

secondaryPreferred

public static TaggableReadPreference secondaryPreferred(DBObject firstTagSet,
                                                        DBObject... remainingTagSets)
Returns:
ReadPreference which reads secondary if available respective of tags, otherwise from primary irrespective of tags.

nearest

public static ReadPreference nearest()
Returns:
ReadPreference which reads nearest node.

valueOf

public static ReadPreference valueOf(String name)

valueOf

public static TaggableReadPreference valueOf(String name,
                                             DBObject firstTagSet,
                                             DBObject... remainingTagSets)

nearest

public static TaggableReadPreference nearest(DBObject firstTagSet,
                                             DBObject... remainingTagSets)
Returns:
ReadPreference which reads nearest node respective of tags.

withTags

@Deprecated
public static ReadPreference withTags(Map<String,String> tags)
Deprecated. As of release 2.9.0, replaced by ReadPreference.secondaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)


withTags

@Deprecated
public static ReadPreference withTags(DBObject tags)
Deprecated. As of release 2.9.0, replaced by ReadPreference.secondaryPreferred(DBObject firstTagSet, DBObject... remainingTagSets)