Documentation ¶
Index ¶
Constants ¶
const ( RAvailable = "available" RLinearizable = "linearizable" RLocal = "local" RMajority = "majority" )
The read concern strings.
RAvailable specifies that the query should return data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
RLinearizable specifies that the query should return data that reflects all successful writes issued with a write concern of "majority" and acknowledged prior to the start of the read operation.
RLocal specifies that the query should return the instance’s most recent data.
RMajority specifies that the query should return the instance’s most recent data acknowledged as having been written to a majority of members in the replica set.
const (
WMajority = "majority"
)
The write concern strings.
WMajority requests acknowledgement that write operations propagate to the majority of mongod instances.
Variables ¶
This section is empty.
Functions ¶
func AreEqual ¶ added in v0.1.37
func AreEqual(c *ClientConfig, d *ClientConfig) bool
AreEqual returns true iff the two configurations are equal.
func Open ¶ added in v0.1.37
func Open(ctx context.Context, cfg *ClientConfig) (keyvalue.Connection, error)
Open opens a connection to mongodb.
Types ¶
type ClientConfig ¶
type ClientConfig struct { AppName string // The application name to identify ourselves as Hosts []string // The hosts Username string // The username Password string // The password PasswordSet bool // Is a password set? PoolSize int // The connection pool size ReadConcern string // The read concern to use WriteConcern string // The write concern to use WriteN int // The number of writes to confirm WriteJournal bool // Journal confirmation? SessionRefreshInterval time.Duration // The session refresh interval }
ClientConfig describes the configuration options we allow a user to set on a client connection.
PoolSize: The maximum size of the connection pool.
ReadConcern: Valid values are given by the constants RAvailable, RLinearizable, RLocal, and RMajority.
WriteConcern: Valid values are given by the constants WMajority.
WriteN: Here the value N must be a positive integer. This requests acknowledgement that write operations propagate to N mongod instances.
WriteJournal: A value of true requests acknowledgement from MongoDB that write operations are written to the journal.
SessionRefreshInterval: The duration after which the mongoDB client session is automatically refreshed. A duration of 0 will disable automatic session refresh.
func DefaultConfig ¶
func DefaultConfig() *ClientConfig
DefaultConfig returns a new client configuration initialised with the default values.
The initial default value for the hosts, username, and password will be read from the environment variables
PCAS_MONGO_HOST = "hostname1[:port1][,...,hostnamek[:portk]]" PCAS_MONGO_USERNAME = "myname" PCAS_MONGO_PASSWORD = "mysecret"
respectively on package init.
Note that if PCAS_MONGO_PASSWORD is set but with value equal to the empty string then it still counts as a valid password, since the empty string is a valid password. You must ensure that PCAS_MONGO_PASSWORD is unset if you do not want to specify an initial default password.
func SetDefaultConfig ¶
func SetDefaultConfig(c *ClientConfig) *ClientConfig
SetDefaultConfig sets the default client configuration to c and returns the old default configuration. This change will be reflected in future calls to DefaultConfig.
func (*ClientConfig) Copy ¶
func (c *ClientConfig) Copy() *ClientConfig
Copy returns a copy of the configuration.
func (*ClientConfig) Hash ¶ added in v0.1.37
func (c *ClientConfig) Hash() uint32
Hash returns a hash for the configuration.
func (*ClientConfig) Validate ¶
func (c *ClientConfig) Validate() error
Validate validates the client configuration, returning an error if there's a problem.