mongodb

package
v0.1.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: CC0-1.0, CC0-1.0 Imports: 21 Imported by: 2

Documentation

Overview

Package mongodb implements the keyvalue interfaces when working with mongodb.

The dataSource should be in the format:

mongodb://[username[:password]@]host1[:port1][,...hostN[:portN]]/database[?param1=value1&...]

Valid parameters are:

  • appname The application name to identify ourselves as.
  • readconcern The read concern.
  • writeconcern The write concern.
  • j Acknowledge journal writes?

Any other parameters will be ignored.

readconcern: The possible values are:

  • available Available 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).
  • linearizable Linearizable 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.
  • local Local specifies that the query should return the instance’s most recent data.
  • majority Majority 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.

writeconcern: The possible values are:

  • majority Majority requests acknowledgement that write operations propagate to the majority of mongod instances.
  • N N a positive integer. Requests acknowledgement that write operations propagate to N mongod instances.

j: The possible values are 'true' or 'false'. A value of true requests acknowledgement from MongoDB that write operations are written to the journal.

Index

Constants

View Source
const (
	RAvailable    = "available"
	RLinearizable = "linearizable"
	RLocal        = "local"
	RMajority     = "majority"
)

The read concern strings.

View Source
const DriverName = "mongodb"

DriverName is the name used to register the driver.

View Source
const (
	WMajority = "majority"
)

The write concern strings.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	AppName      string   // The application name to identify ourselves via
	Hosts        []string // The hosts
	Username     string   // The username
	Password     string   // The password
	PasswordSet  bool     // Is a password set?
	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?
}

ClientConfig describes the configuration options we allow a user to set on a client connection.

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 ParseURL

func ParseURL(s string) (*ClientConfig, string, error)

ParseURL parses the given URL into client configuration options and database name.

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) ToClientOptions

func (c *ClientConfig) ToClientOptions() *options.ClientOptions

ToClientOptions converts the configuration to an *options.ClientOptions.

func (*ClientConfig) ToReadConcern

func (c *ClientConfig) ToReadConcern() *readconcern.ReadConcern

ToReadConcern converts the configuration to a *readconcern.ReadConcern.

func (*ClientConfig) ToWriteConcern

func (c *ClientConfig) ToWriteConcern() *writeconcern.WriteConcern

ToWriteConcern converts the configuration to a *writeconcern.WriteConcern.

func (*ClientConfig) URL

func (c *ClientConfig) URL(dbName string) string

URL returns a URL representation of the configuration, connecting to the given database.

func (*ClientConfig) Validate

func (c *ClientConfig) Validate() error

Validate validates the client configuration, returning an error if there's a problem.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL