package readpref
import "go.mongodb.org/mongo-driver/mongo/readpref"
Package readpref defines read preferences for MongoDB queries.
Index ¶
- Variables
- type Mode
- func ModeFromString(mode string) (Mode, error)
- func (mode Mode) IsValid() bool
- func (mode Mode) String() string
- type Option
- func WithHedgeEnabled(hedgeEnabled bool) Option
- func WithMaxStaleness(ms time.Duration) Option
- func WithTagSets(tagSets ...tag.Set) Option
- func WithTags(tags ...string) Option
- type ReadPref
- func Nearest(opts ...Option) *ReadPref
- func New(mode Mode, opts ...Option) (*ReadPref, error)
- func Primary() *ReadPref
- func PrimaryPreferred(opts ...Option) *ReadPref
- func Secondary(opts ...Option) *ReadPref
- func SecondaryPreferred(opts ...Option) *ReadPref
- func (r *ReadPref) HedgeEnabled() *bool
- func (r *ReadPref) MaxStaleness() (time.Duration, bool)
- func (r *ReadPref) Mode() Mode
- func (r *ReadPref) String() string
- func (r *ReadPref) TagSets() []tag.Set
Variables ¶
ErrInvalidTagSet indicates that an invalid set of tags was specified.
Types ¶
type Mode ¶
type Mode uint8
Mode indicates the user's preference on reads.
const ( // PrimaryMode indicates that only a primary is // considered for reading. This is the default // mode. PrimaryMode Mode // PrimaryPreferredMode indicates that if a primary // is available, use it; otherwise, eligible // secondaries will be considered. PrimaryPreferredMode // SecondaryMode indicates that only secondaries // should be considered. SecondaryMode // SecondaryPreferredMode indicates that only secondaries // should be considered when one is available. If none // are available, then a primary will be considered. SecondaryPreferredMode // NearestMode indicates that all primaries and secondaries // will be considered. NearestMode )
Mode constants
func ModeFromString ¶
ModeFromString returns a mode corresponding to mode.
func (Mode) IsValid ¶
IsValid checks whether the mode is valid.
func (Mode) String ¶
String returns the string representation of mode.
type Option ¶
Option configures a read preference
func WithHedgeEnabled ¶
WithHedgeEnabled specifies whether or not hedged reads should be enabled in the server. This feature requires MongoDB server version 4.4 or higher. For more information about hedged reads, see https://docs.mongodb.com/manual/core/sharded-cluster-query-router/#mongos-hedged-reads. If not specified, the default is to not send a value to the server, which will result in the server defaults being used.
func WithMaxStaleness ¶
WithMaxStaleness sets the maximum staleness a server is allowed.
func WithTagSets ¶
WithTagSets sets the tag sets used to match a server. The last call to WithTags or WithTagSets overrides all previous calls to either method.
func WithTags ¶
WithTags sets a single tag set used to match a server. The last call to WithTags or WithTagSets overrides all previous calls to either method.
type ReadPref ¶
type ReadPref struct {
// contains filtered or unexported fields
}
ReadPref determines which servers are considered suitable for read operations.
func Nearest ¶
Nearest constructs a read preference with a NearestMode.
func New ¶
New creates a new ReadPref.
func Primary ¶
func Primary() *ReadPref
Primary constructs a read preference with a PrimaryMode.
func PrimaryPreferred ¶
PrimaryPreferred constructs a read preference with a PrimaryPreferredMode.
func Secondary ¶
Secondary constructs a read preference with a SecondaryMode.
func SecondaryPreferred ¶
SecondaryPreferred constructs a read preference with a SecondaryPreferredMode.
func (*ReadPref) HedgeEnabled ¶
HedgeEnabled returns whether or not hedged reads are enabled for this read preference. If this option was not specified during read preference construction, nil is returned.
func (*ReadPref) MaxStaleness ¶
MaxStaleness is the maximum amount of time to allow a server to be considered eligible for selection. The second return value indicates if this value has been set.
func (*ReadPref) Mode ¶
Mode indicates the mode of the read preference.
func (*ReadPref) String ¶
String returns a human-readable description of the read preference.
func (*ReadPref) TagSets ¶
TagSets are multiple tag sets indicating which servers should be considered.
Source Files ¶
mode.go options.go readpref.go
- Version
- v1.9.3
- Published
- Nov 2, 2022
- Platform
- windows/amd64
- Imports
- 6 packages
- Last checked
- 1 minute ago –
Tools for package owners.