options

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCausalConsistency = true

DefaultCausalConsistency is the default value for the CausalConsistency option.

View Source
var DefaultChunkSize int32 = 255 * 1024 // 255 KiB

DefaultChunkSize is the default size of each file chunk in bytes.

View Source
var DefaultName = "fs"

DefaultName is the default name for a GridFS bucket.

View Source
var DefaultOrdered = true

DefaultOrdered is the default order for a BulkWriteOptions struct created from BulkWrite.

View Source
var DefaultRevision int32 = -1

DefaultRevision is the default revision number for a download by name operation.

Functions

This section is empty.

Types

type AggregateOptions

type AggregateOptions struct {
	AllowDiskUse             *bool          // Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp subdirectory in the dbPath directory
	BatchSize                *int32         // The number of documents to return per batch
	BypassDocumentValidation *bool          // If true, allows the write to opt-out of document level validation. This only applies when the $out stage is specified
	Collation                *Collation     // Specifies a collation
	MaxTime                  *time.Duration // The maximum amount of time to allow the query to run
	MaxAwaitTime             *time.Duration // The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query
	Comment                  *string        // Enables users to specify an arbitrary string to help trace the operation through the database profiler, currentOp and logs.
	Hint                     interface{}    // The index to use for the aggregation. The hint does not apply to $lookup and $graphLookup stages
}

AggregateOptions represents all possible options to the Aggregate() function.

func Aggregate

func Aggregate() *AggregateOptions

Aggregate returns a pointer to a new AggregateOptions

func MergeAggregateOptions

func MergeAggregateOptions(opts ...*AggregateOptions) *AggregateOptions

MergeAggregateOptions combines the argued AggregateOptions into a single AggregateOptions in a last-one-wins fashion

func (*AggregateOptions) SetAllowDiskUse

func (ao *AggregateOptions) SetAllowDiskUse(b bool) *AggregateOptions

SetAllowDiskUse enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp subdirectory in the dbPath directory

func (*AggregateOptions) SetBatchSize

func (ao *AggregateOptions) SetBatchSize(i int32) *AggregateOptions

SetBatchSize specifies the number of documents to return per batch

func (*AggregateOptions) SetBypassDocumentValidation

func (ao *AggregateOptions) SetBypassDocumentValidation(b bool) *AggregateOptions

SetBypassDocumentValidation allows the write to opt-out of document level validation. This only applies when the $out stage is specified Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

func (*AggregateOptions) SetCollation

func (ao *AggregateOptions) SetCollation(c *Collation) *AggregateOptions

SetCollation specifies a collation. Valid for server versions >= 3.4

func (*AggregateOptions) SetComment

func (ao *AggregateOptions) SetComment(s string) *AggregateOptions

SetComment enables users to specify an arbitrary string to help trace the operation through the database profiler, currentOp and logs.

func (*AggregateOptions) SetHint

func (ao *AggregateOptions) SetHint(h interface{}) *AggregateOptions

SetHint specifies the index to use for the aggregation. The hint does not apply to $lookup and $graphLookup stages

func (*AggregateOptions) SetMaxAwaitTime

func (ao *AggregateOptions) SetMaxAwaitTime(d time.Duration) *AggregateOptions

SetMaxAwaitTime specifies the maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query For servers < 3.2, this option is ignored

func (*AggregateOptions) SetMaxTime

func (ao *AggregateOptions) SetMaxTime(d time.Duration) *AggregateOptions

SetMaxTime specifies the maximum amount of time to allow the query to run

type ArrayFilters

type ArrayFilters struct {
	Registry *bsoncodec.Registry // The registry to use for converting filters. Defaults to bson.DefaultRegistry.
	Filters  []interface{}       // The filters to apply
}

ArrayFilters is used to hold filters for the array filters CRUD option. If a registry is nil, bson.DefaultRegistry will be used when converting the filter interfaces to BSON.

func (*ArrayFilters) ToArray

func (af *ArrayFilters) ToArray() ([]bson.Raw, error)

ToArray builds a []bson.Raw from the provided ArrayFilters.

func (*ArrayFilters) ToArrayDocument added in v1.1.0

func (af *ArrayFilters) ToArrayDocument() (bson.Raw, error)

ToArrayDocument builds a BSON array for the array filters CRUD option. If the registry for af is nil, bson.DefaultRegistry will be used when converting the filter interfaces to BSON.

type AutoEncryptionOptions added in v1.2.0

type AutoEncryptionOptions struct {
	KeyVaultClientOptions *ClientOptions
	KeyVaultNamespace     string
	KmsProviders          map[string]map[string]interface{}
	SchemaMap             map[string]interface{}
	BypassAutoEncryption  *bool
	ExtraOptions          map[string]interface{}
}

AutoEncryptionOptions represents options used to configure auto encryption/decryption behavior for a mongo.Client instance.

Automatic encryption is an enterprise only feature that only applies to operations on a collection. Automatic encryption is not supported for operations on a database or view, and operations that are not bypassed will result in error. Too bypass automatic encryption for all operations, set BypassAutoEncryption=true.

Auto encryption requires the authenticated user to have the listCollections privilege action.

If automatic encryption fails on an operation, use a MongoClient configured with bypassAutoEncryption=true and use ClientEncryption.encrypt() to manually encrypt values.

Enabling Client Side Encryption reduces the maximum document and message size (using a maxBsonObjectSize of 2MiB and maxMessageSizeBytes of 6MB) and may have a negative performance impact.

func AutoEncryption added in v1.2.0

func AutoEncryption() *AutoEncryptionOptions

AutoEncryption creates a new AutoEncryptionOptions configured with default values.

func MergeAutoEncryptionOptions added in v1.2.0

func MergeAutoEncryptionOptions(opts ...*AutoEncryptionOptions) *AutoEncryptionOptions

MergeAutoEncryptionOptions combines the argued AutoEncryptionOptions in a last-one wins fashion.

func (*AutoEncryptionOptions) SetBypassAutoEncryption added in v1.2.0

func (a *AutoEncryptionOptions) SetBypassAutoEncryption(bypass bool) *AutoEncryptionOptions

SetBypassAutoEncryption specifies whether or not auto encryption should be done.

func (*AutoEncryptionOptions) SetExtraOptions added in v1.2.0

func (a *AutoEncryptionOptions) SetExtraOptions(extraOpts map[string]interface{}) *AutoEncryptionOptions

SetExtraOptions specifies a map of options to configure the mongocryptd process.

func (*AutoEncryptionOptions) SetKeyVaultClientOptions added in v1.2.0

func (a *AutoEncryptionOptions) SetKeyVaultClientOptions(opts *ClientOptions) *AutoEncryptionOptions

SetKeyVaultClientOptions specifies options for the client used to communicate with the key vault collection. If this is not set, the client used to do encryption will be re-used for key vault communication.

func (*AutoEncryptionOptions) SetKeyVaultNamespace added in v1.2.0

func (a *AutoEncryptionOptions) SetKeyVaultNamespace(ns string) *AutoEncryptionOptions

SetKeyVaultNamespace specifies the namespace of the key vault collection. This is required.

func (*AutoEncryptionOptions) SetKmsProviders added in v1.2.0

func (a *AutoEncryptionOptions) SetKmsProviders(providers map[string]map[string]interface{}) *AutoEncryptionOptions

SetKmsProviders specifies options for KMS providers. This is required.

func (*AutoEncryptionOptions) SetSchemaMap added in v1.2.0

func (a *AutoEncryptionOptions) SetSchemaMap(schemaMap map[string]interface{}) *AutoEncryptionOptions

SetSchemaMap specifies a map from namespace to local schema document. Schemas supplied in the schemaMap only apply to configuring automatic encryption for client side encryption. Other validation rules in the JSON schema will not be enforced by the driver and will result in an error.

Supplying a schemaMap provides more security than relying on JSON Schemas obtained from the server. It protects against a malicious server advertising a false JSON Schema, which could trick the client into sending unencrypted data that should be encrypted.

type BucketOptions

type BucketOptions struct {
	Name           *string                    // The bucket name. Defaults to "fs".
	ChunkSizeBytes *int32                     // The chunk size in bytes. Defaults to 255KB.
	WriteConcern   *writeconcern.WriteConcern // The write concern for the bucket. Defaults to the write concern of the database.
	ReadConcern    *readconcern.ReadConcern   // The read concern for the bucket. Defaults to the read concern of the database.
	ReadPreference *readpref.ReadPref         // The read preference for the bucket. Defaults to the read preference of the database.
}

BucketOptions represents all possible options to configure a GridFS bucket.

func GridFSBucket

func GridFSBucket() *BucketOptions

GridFSBucket creates a new *BucketOptions

func MergeBucketOptions

func MergeBucketOptions(opts ...*BucketOptions) *BucketOptions

MergeBucketOptions combines the given *BucketOptions into a single *BucketOptions. If the name or chunk size is not set in any of the given *BucketOptions, the resulting *BucketOptions will have name "fs" and chunk size 255KB.

func (*BucketOptions) SetChunkSizeBytes

func (b *BucketOptions) SetChunkSizeBytes(i int32) *BucketOptions

SetChunkSizeBytes sets the chunk size in bytes for the bucket. Defaults to 255KB if not set.

func (*BucketOptions) SetName

func (b *BucketOptions) SetName(name string) *BucketOptions

SetName sets the name for the bucket. Defaults to "fs" if not set.

func (*BucketOptions) SetReadConcern

func (b *BucketOptions) SetReadConcern(rc *readconcern.ReadConcern) *BucketOptions

SetReadConcern sets the read concern for the bucket.

func (*BucketOptions) SetReadPreference

func (b *BucketOptions) SetReadPreference(rp *readpref.ReadPref) *BucketOptions

SetReadPreference sets the read preference for the bucket.

func (*BucketOptions) SetWriteConcern

func (b *BucketOptions) SetWriteConcern(wc *writeconcern.WriteConcern) *BucketOptions

SetWriteConcern sets the write concern for the bucket.

type BulkWriteOptions

type BulkWriteOptions struct {
	BypassDocumentValidation *bool // If true, allows the write to opt out of document-level validation.
	Ordered                  *bool // If true, when a write fails, return without performing remaining writes. Defaults to true.
}

BulkWriteOptions represent all possible options for a bulkWrite operation.

func BulkWrite

func BulkWrite() *BulkWriteOptions

BulkWrite creates a new *BulkWriteOptions

func MergeBulkWriteOptions

func MergeBulkWriteOptions(opts ...*BulkWriteOptions) *BulkWriteOptions

MergeBulkWriteOptions combines the given *BulkWriteOptions into a single *BulkWriteOptions in a last one wins fashion.

func (*BulkWriteOptions) SetBypassDocumentValidation

func (b *BulkWriteOptions) SetBypassDocumentValidation(bypass bool) *BulkWriteOptions

SetBypassDocumentValidation specifies if the write should opt out of document-level validation. Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

func (*BulkWriteOptions) SetOrdered

func (b *BulkWriteOptions) SetOrdered(ordered bool) *BulkWriteOptions

SetOrdered configures the ordered option. If true, when a write fails, the function will return without attempting remaining writes. Defaults to true.

type ChangeStreamOptions

type ChangeStreamOptions struct {
	BatchSize            *int32               // The number of documents to return per batch
	Collation            *Collation           // Specifies a collation
	FullDocument         *FullDocument        // When set to ‘updateLookup’, the change notification for partial updates will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred.
	MaxAwaitTime         *time.Duration       // The maximum amount of time for the server to wait on new documents to satisfy a change stream query
	ResumeAfter          interface{}          // Specifies the logical starting point for the new change stream
	StartAtOperationTime *primitive.Timestamp // Ensures that a change stream will only provide changes that occurred after a timestamp.
	StartAfter           interface{}          // Specifies a resume token. The started change stream will return the first notification after the token.
}

ChangeStreamOptions represents all possible options to a change stream

func ChangeStream

func ChangeStream() *ChangeStreamOptions

ChangeStream returns a pointer to a new ChangeStreamOptions

func MergeChangeStreamOptions

func MergeChangeStreamOptions(opts ...*ChangeStreamOptions) *ChangeStreamOptions

MergeChangeStreamOptions combines the argued ChangeStreamOptions into a single ChangeStreamOptions in a last-one-wins fashion

func (*ChangeStreamOptions) SetBatchSize

func (cso *ChangeStreamOptions) SetBatchSize(i int32) *ChangeStreamOptions

SetBatchSize specifies the number of documents to return per batch

func (*ChangeStreamOptions) SetCollation

func (cso *ChangeStreamOptions) SetCollation(c Collation) *ChangeStreamOptions

SetCollation specifies a collation

func (*ChangeStreamOptions) SetFullDocument

func (cso *ChangeStreamOptions) SetFullDocument(fd FullDocument) *ChangeStreamOptions

SetFullDocument specifies the fullDocument option. When set to ‘updateLookup’, the change notification for partial updates will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred.

func (*ChangeStreamOptions) SetMaxAwaitTime

func (cso *ChangeStreamOptions) SetMaxAwaitTime(d time.Duration) *ChangeStreamOptions

SetMaxAwaitTime specifies the maximum amount of time for the server to wait on new documents to satisfy a change stream query

func (*ChangeStreamOptions) SetResumeAfter

func (cso *ChangeStreamOptions) SetResumeAfter(rt interface{}) *ChangeStreamOptions

SetResumeAfter specifies the logical starting point for the new change stream

func (*ChangeStreamOptions) SetStartAfter added in v1.1.0

func (cso *ChangeStreamOptions) SetStartAfter(sa interface{}) *ChangeStreamOptions

SetStartAfter specifies a resume token. The resulting change stream will return the first notification after the token. Cannot be used in conjunction with ResumeAfter.

func (*ChangeStreamOptions) SetStartAtOperationTime

func (cso *ChangeStreamOptions) SetStartAtOperationTime(t *primitive.Timestamp) *ChangeStreamOptions

SetStartAtOperationTime ensures that a change stream will only provide changes that occurred after a specified timestamp.

type ClientEncryptionOptions added in v1.2.0

type ClientEncryptionOptions struct {
	KeyVaultNamespace string
	KmsProviders      map[string]map[string]interface{}
}

ClientEncryptionOptions represents all possible options used to configure a ClientEncryption instance.

func ClientEncryption added in v1.2.0

func ClientEncryption() *ClientEncryptionOptions

ClientEncryption creates a new ClientEncryptionOptions instance.

func MergeClientEncryptionOptions added in v1.2.0

func MergeClientEncryptionOptions(opts ...*ClientEncryptionOptions) *ClientEncryptionOptions

MergeClientEncryptionOptions combines the argued ClientEncryptionOptions in a last-one wins fashion.

func (*ClientEncryptionOptions) SetKeyVaultNamespace added in v1.2.0

func (c *ClientEncryptionOptions) SetKeyVaultNamespace(ns string) *ClientEncryptionOptions

SetKeyVaultNamespace specifies the namespace of the key vault collection. This is required.

func (*ClientEncryptionOptions) SetKmsProviders added in v1.2.0

func (c *ClientEncryptionOptions) SetKmsProviders(providers map[string]map[string]interface{}) *ClientEncryptionOptions

SetKmsProviders specifies options for KMS providers. This is required.

type ClientOptions

type ClientOptions struct {
	AppName                *string
	Auth                   *Credential
	ConnectTimeout         *time.Duration
	Compressors            []string
	Dialer                 ContextDialer
	HeartbeatInterval      *time.Duration
	Hosts                  []string
	LocalThreshold         *time.Duration
	MaxConnIdleTime        *time.Duration
	MaxPoolSize            *uint64
	MinPoolSize            *uint64
	PoolMonitor            *event.PoolMonitor
	Monitor                *event.CommandMonitor
	ReadConcern            *readconcern.ReadConcern
	ReadPreference         *readpref.ReadPref
	Registry               *bsoncodec.Registry
	ReplicaSet             *string
	RetryWrites            *bool
	RetryReads             *bool
	ServerSelectionTimeout *time.Duration
	Direct                 *bool
	SocketTimeout          *time.Duration
	TLSConfig              *tls.Config
	WriteConcern           *writeconcern.WriteConcern
	ZlibLevel              *int
	ZstdLevel              *int
	AutoEncryptionOptions  *AutoEncryptionOptions

	// These options are for internal use only and should not be set. They are deprecated and are
	// not part of the stability guarantee. They may be removed in the future.
	AuthenticateToAnything *bool
	Deployment             driver.Deployment
	// contains filtered or unexported fields
}

ClientOptions contains options to configure a Client instance. Each option can be set through setter functions. See documentation for each setter function for an explanation of the option.

func Client

func Client() *ClientOptions

Client creates a new ClientOptions instance.

func MergeClientOptions

func MergeClientOptions(opts ...*ClientOptions) *ClientOptions

MergeClientOptions combines the given *ClientOptions into a single *ClientOptions in a last one wins fashion. The specified options are merged with the existing options on the collection, with the specified options taking precedence.

func (*ClientOptions) ApplyURI

func (c *ClientOptions) ApplyURI(uri string) *ClientOptions

ApplyURI parses the given URI and sets options accordingly. The URI can contain host names, IPv4/IPv6 literals, or an SRV record that will be resolved when the Client is created. When using an SRV record, TLS support is implictly enabled. Specify the "tls=false" URI option to override this.

If the connection string contains any options that have previously been set, it will overwrite them. Options that correspond to multiple URI parameters, such as WriteConcern, will be completely overwritten if any of the query parameters are specified. If an option is set on ClientOptions after this method is called, that option will override any option applied via the connection string.

If the URI format is incorrect or there are conflicing options specified in the URI an error will be recorded and can be retrieved by calling Validate.

For more information about the URI format, see https://docs.mongodb.com/manual/reference/connection-string/. See mongo.Connect documentation for examples of using URIs for different Client configurations.

func (*ClientOptions) SetAppName

func (c *ClientOptions) SetAppName(s string) *ClientOptions

SetAppName specifies an application name that is sent to the server when creating new connections. It is used by the server to log connection and profiling information (e.g. slow query logs). This can also be set through the "appName" URI option (e.g "appName=example_application"). The default is empty, meaning no app name will be sent.

func (*ClientOptions) SetAuth

func (c *ClientOptions) SetAuth(auth Credential) *ClientOptions

SetAuth specifies a Credential containing options for configuring authentication. See the options.Credential documentation for more information about Credential fields. The default is an empty Credential, meaning no authentication will be configured.

func (*ClientOptions) SetAutoEncryptionOptions added in v1.2.0

func (c *ClientOptions) SetAutoEncryptionOptions(opts *AutoEncryptionOptions) *ClientOptions

SetAutoEncryptionOptions specifies an AutoEncryptionOptions instance to automatically encrypt and decrypt commands and their results. See the options.AutoEncryptionOptions documentation for more information about the supported options.

func (*ClientOptions) SetCompressors

func (c *ClientOptions) SetCompressors(comps []string) *ClientOptions

SetCompressors sets the compressors that can be used when communicating with a server. Valid values are:

1. "snappy" - requires server version >= 3.4

2. "zlib" - requires server version >= 3.6

3. "zstd" - requires driver version >= 1.2.0, server version >= 4.2, and cgo support to be enabled.

To use compression, it must be enabled on the server as well. If this option is specified, the driver will perform a negotiation with the server to determine a common list of of compressors and will use the first one in that list when performing operations. See https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-networkmessagecompressors for more information about how to enable this feature on the server.

This can also be set through the "compressors" URI option (e.g. "compressors=zstd,zlib,snappy"). The default is an empty slice, meaning no compression will be enabled.

func (*ClientOptions) SetConnectTimeout

func (c *ClientOptions) SetConnectTimeout(d time.Duration) *ClientOptions

SetConnectTimeout specifies a timeout that is used for creating connections to the server. If a custom Dialer is specified through SetDialer, this option must not be used. This can be set through ApplyURI with the "connectTimeoutMS" (e.g "connectTimeoutMS=30") option. If set to 0, no timeout will be used. The default is 30 seconds.

func (*ClientOptions) SetDialer

func (c *ClientOptions) SetDialer(d ContextDialer) *ClientOptions

SetDialer specifies a custom ContextDialer to be used to create new connections to the server. The default is a net.Dialer instance with a 300 second keepalive time.

func (*ClientOptions) SetDirect

func (c *ClientOptions) SetDirect(b bool) *ClientOptions

SetDirect specifies whether or not a direct connect should be made. To use this option, a URI with a single host must be specified through ApplyURI. If set to true, the driver will only connect to the host provided in the URI and will not discover other hosts in the cluster. This can also be set through the "connect" URI option with the following values:

1. "connect=direct" for direct connections

2. "connect=automatic" for automatic discovery.

The default is false ("automatic" in the connection string).

func (*ClientOptions) SetHeartbeatInterval

func (c *ClientOptions) SetHeartbeatInterval(d time.Duration) *ClientOptions

SetHeartbeatInterval specifies the amount of time to wait between periodic background server checks. This can also be set through the "heartbeatIntervalMS" URI option (e.g. "heartbeatIntervalMS=10000"). The default is 10 seconds.

func (*ClientOptions) SetHosts

func (c *ClientOptions) SetHosts(s []string) *ClientOptions

SetHosts specifies a list of host names or IP addresses for servers in a cluster. Both IPv4 and IPv6 addresses are supported. IPv6 literals must be enclosed in '[]' following RFC-2732 syntax.

Hosts can also be specified as a comma-separated list in a URI. For example, to include "localhost:27017" and "localhost:27018", a URI could be "mongodb://localhost:27017,localhost:27018". The default is ["localhost:27017"]

func (*ClientOptions) SetLocalThreshold

func (c *ClientOptions) SetLocalThreshold(d time.Duration) *ClientOptions

SetLocalThreshold specifies the width of the 'latency window': when choosing between multiple suitable servers for an operation, this is the acceptable non-negative delta between shortest and longest average round-trip times. A server within the latency window is selected randomly. This can also be set through the "localThresholdMS" URI option (e.g. "localThresholdMS=15000"). The default is 15 milliseconds.

func (*ClientOptions) SetMaxConnIdleTime

func (c *ClientOptions) SetMaxConnIdleTime(d time.Duration) *ClientOptions

SetMaxConnIdleTime specifies the maximum amount of time that a connection will remain idle in a connection pool before it is removed from the pool and closed. This can also be set through the "maxIdleTimeMS" URI option (e.g. "maxIdleTimeMS=10000"). The default is 0, meaning a connection can remain unused indefinitely.

func (*ClientOptions) SetMaxPoolSize

func (c *ClientOptions) SetMaxPoolSize(u uint64) *ClientOptions

SetMaxPoolSize specifies that maximum number of connections allowed in the driver's connection pool to each server. Requests to a server will block if this maximum is reached. This can also be set through the "maxPoolSize" URI option (e.g. "maxPoolSize=100"). The default is 100. If this is 0, it will be set to math.MaxInt64.

func (*ClientOptions) SetMinPoolSize added in v1.1.0

func (c *ClientOptions) SetMinPoolSize(u uint64) *ClientOptions

SetMinPoolSize specifies the minimum number of connections allowed in the driver's connection pool to each server. If this is non-zero, each server's pool will be maintained in the background to ensure that the size does not fall below the minimum. This can also be set through the "minPoolSize" URI option (e.g. "minPoolSize=100"). The default is 0.

func (*ClientOptions) SetMonitor

func (c *ClientOptions) SetMonitor(m *event.CommandMonitor) *ClientOptions

SetMonitor specifies a CommandMonitor to receive command events. See the event.CommandMonitor documentation for more information about the structure of the monitor and events that can be received.

func (*ClientOptions) SetPoolMonitor added in v1.1.0

func (c *ClientOptions) SetPoolMonitor(m *event.PoolMonitor) *ClientOptions

SetPoolMonitor specifies a PoolMonitor to receive connection pool events. See the event.PoolMonitor documentation for more information about the structure of the monitor and events that can be received.

func (*ClientOptions) SetReadConcern

func (c *ClientOptions) SetReadConcern(rc *readconcern.ReadConcern) *ClientOptions

SetReadConcern specifies the read concern to use for read operations. A read concern level can also be set through the "readConcernLevel" URI option (e.g. "readConcernLevel=majority"). The default is nil, meaning the server will use its configured default.

func (*ClientOptions) SetReadPreference

func (c *ClientOptions) SetReadPreference(rp *readpref.ReadPref) *ClientOptions

SetReadPreference specifies the read preference to use for read operations. This can also be set through the following URI options:

1. "readPreference" - Specifiy the read preference mode (e.g. "readPreference=primary").

2. "readPreferenceTags": Specify one or more read preference tags (e.g. "readPreferenceTags=region:south,datacenter:A").

3. "maxStalenessSeconds" (or "maxStaleness"): Specify a maximum replication lag for reads from secondaries in a replica set (e.g. "maxStalenessSeconds=10").

The default is readpref.Primary(). See https://docs.mongodb.com/manual/core/read-preference/#read-preference for more information about read preferences.

func (*ClientOptions) SetRegistry

func (c *ClientOptions) SetRegistry(registry *bsoncodec.Registry) *ClientOptions

SetRegistry specifies the BSON registry to use for BSON marshalling/unmarshalling operations. The default is bson.DefaultRegistry.

func (*ClientOptions) SetReplicaSet

func (c *ClientOptions) SetReplicaSet(s string) *ClientOptions

SetReplicaSet specifies the replica set name for the cluster. If specified, the cluster will be treated as a replica set and the driver will automatically discover all servers in the set, starting with the nodes specified through ApplyURI or SetHosts. All nodes in the replica set must have the same replica set name, or they will not be considered as part of the set by the Client. This can also be set through the "replicaSet" URI option (e.g. "replicaSet=replset"). The default is empty.

func (*ClientOptions) SetRetryReads added in v1.2.0

func (c *ClientOptions) SetRetryReads(b bool) *ClientOptions

SetRetryReads specifies whether supported read operations should be retried once on certain errors, such as network errors.

Supported operations are Find, FindOne, Aggregate without a $out stage, Distinct, CountDocuments, EstimatedDocumentCount, Watch (for Client, Database, and Collection), ListCollections, and ListDatabases. Note that operations run through RunCommand are not retried.

This option requires server version >= 3.6 and driver version >= 1.1.0. The default is true.

func (*ClientOptions) SetRetryWrites

func (c *ClientOptions) SetRetryWrites(b bool) *ClientOptions

SetRetryWrites specifies whether supported write operations should be retried once on certain errors, such as network errors.

Supported operations are InsertOne, UpdateOne, ReplaceOne, DeleteOne, FindOneAndDelete, FindOneAndReplace, FindOneAndDelete, InsertMany, and BulkWrite. Note that BulkWrite requests must not include UpdateManyModel or DeleteManyModel instances to be considered retryable. Unacknowledged writes will not be retried, even if this option is set to true.

This option requires server version >= 3.6 and a replica set or sharded cluster and will be ignored for any other cluster type. This can also be set through the "retryWrites" URI option (e.g. "retryWrites=true"). The default is true.

func (*ClientOptions) SetServerSelectionTimeout

func (c *ClientOptions) SetServerSelectionTimeout(d time.Duration) *ClientOptions

SetServerSelectionTimeout specifies how long the driver will wait to find an available, suitable server to execute an operation. This can also be set through the "serverSelectionTimeoutMS" URI option (e.g. "serverSelectionTimeoutMS=30000"). The default value is 30 seconds.

func (*ClientOptions) SetSocketTimeout

func (c *ClientOptions) SetSocketTimeout(d time.Duration) *ClientOptions

SetSocketTimeout specifies how long the driver will wait for a socket read or write to return before returning a network error. This can also be set through the "socketTimeoutMS" URI option (e.g. "socketTimeoutMS=1000"). The default value is 0, meaning no timeout is used and socket operations can block indefinitely.

func (*ClientOptions) SetTLSConfig

func (c *ClientOptions) SetTLSConfig(cfg *tls.Config) *ClientOptions

SetTLSConfig specifies a tls.Config instance to use use to configure TLS on all connections created to the cluster. This can also be set through the following URI options:

1. "tls" (or "ssl"): Specify if TLS should be used (e.g. "tls=true").

2. "tlsCertificateKeyFile" (or "sslClientCertificateKeyFile"): Specify the path to the client certificate key file or the client private key file. If they are both needed, the files should be concatentated into one file. For example, "tlsCertificateKeyFile=/path/to/ca.pem".

3. "tlsCertificateKeyFilePassword" (or "sslClientCertificateKeyPassword"): Specify the password to decrypt the client private key file (e.g. "tlsCertificateKeyFilePassword=password").

4. "tlsCaFile" (or "sslCertificateAuthorityFile"): Specify the path to a single or bundle of certificate authorities to be considered trusted when making a TLS connection (e.g. "tlsCaFile=/path/to/caFile").

5. "tlsInsecure" (or "sslInsecure"): Specifies whether or not certificates and hostnames received from the server should be validated. If true (e.g. "tlsInsecure=true"), the TLS library will accept any certificate presented by the server and any host name in that certificate. Note that setting this to true makes TLS susceptible to man-in-the-middle attacks and should only be done for testing.

The default is nil, meaning no TLS will be enabled.

func (*ClientOptions) SetWriteConcern

func (c *ClientOptions) SetWriteConcern(wc *writeconcern.WriteConcern) *ClientOptions

SetWriteConcern specifies the write concern to use to for write operations. This can also be se through the following URI options:

1. "w": Specify the number of nodes in the cluster that must acknowledge write operations before the operation returns or "majority" to specify that a majority of the nodes must acknowledge writes. This can either be an integer (e.g. "w=10") or the string "majority" (e.g. "w=majority").

2. "wTimeoutMS": Specify how long write operations should wait for the correct number of nodes to acknowledge the operation (e.g. "wTimeoutMS=1000").

3. "journal": Specifies whether or not write operations should be written to an on-disk journal on the server before returning (e.g. "journal=true").

The default is nil, meaning the server will use its configured default.

func (*ClientOptions) SetZlibLevel

func (c *ClientOptions) SetZlibLevel(level int) *ClientOptions

SetZlibLevel specifies the level for the zlib compressor. This option is ignored if zlib is not specified as a compressor through ApplyURI or SetCompressors. Supported values are -1 through 9, inclusive. -1 tells the zlib library to use its default, 0 means no compression, 1 means best speed, and 9 means best compression. This can also be set through the "zlibCompressionLevel" URI option (e.g. "zlibCompressionLevel=-1"). Defaults to -1.

func (*ClientOptions) SetZstdLevel added in v1.2.0

func (c *ClientOptions) SetZstdLevel(level int) *ClientOptions

SetZstdLevel sets the level for the zstd compressor. This option is ignored if zstd is not specified as a compressor through ApplyURI or SetCompressors. Supported values are 1 through 20, inclusive. 1 means best speed and 20 means best compression. This can also be set through the "zstdCompressionLevel" URI option. Defaults to 6.

func (*ClientOptions) Validate

func (c *ClientOptions) Validate() error

Validate validates the client options. This method will return the first error found.

type Collation

type Collation struct {
	Locale          string `bson:",omitempty"` // The locale
	CaseLevel       bool   `bson:",omitempty"` // The case level
	CaseFirst       string `bson:",omitempty"` // The case ordering
	Strength        int    `bson:",omitempty"` // The number of comparision levels to use
	NumericOrdering bool   `bson:",omitempty"` // Whether to order numbers based on numerical order and not collation order
	Alternate       string `bson:",omitempty"` // Whether spaces and punctuation are considered base characters
	MaxVariable     string `bson:",omitempty"` // Which characters are affected by alternate: "shifted"
	Normalization   bool   `bson:",omitempty"` // Causes text to be normalized into Unicode NFD
	Backwards       bool   `bson:",omitempty"` // Causes secondary differences to be considered in reverse order, as it is done in the French language
}

Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks.

func (*Collation) ToDocument

func (co *Collation) ToDocument() bson.Raw

ToDocument converts the Collation to a bson.Raw.

type CollectionOptions

type CollectionOptions struct {
	ReadConcern    *readconcern.ReadConcern   // The read concern for operations in the collection.
	WriteConcern   *writeconcern.WriteConcern // The write concern for operations in the collection.
	ReadPreference *readpref.ReadPref         // The read preference for operations in the collection.
	Registry       *bsoncodec.Registry        // The registry to be used to construct BSON encoders and decoders for the collection.
}

CollectionOptions represent all possible options to configure a Collection.

func Collection

func Collection() *CollectionOptions

Collection creates a new CollectionOptions instance

func MergeCollectionOptions

func MergeCollectionOptions(opts ...*CollectionOptions) *CollectionOptions

MergeCollectionOptions combines the *CollectionOptions arguments into a single *CollectionOptions in a last one wins fashion.

func (*CollectionOptions) SetReadConcern

SetReadConcern sets the read concern for the collection.

func (*CollectionOptions) SetReadPreference

func (c *CollectionOptions) SetReadPreference(rp *readpref.ReadPref) *CollectionOptions

SetReadPreference sets the read preference for the collection.

func (*CollectionOptions) SetRegistry

SetRegistry sets the bsoncodec Registry for the collection.

func (*CollectionOptions) SetWriteConcern

SetWriteConcern sets the write concern for the collection.

type ContextDialer

type ContextDialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

ContextDialer is an interface that can be implemented by types that can create connections. It should be used to provide a custom dialer when configuring a Client.

DialContext should return a connection to the provided address on the given network.

type CountOptions

type CountOptions struct {
	Collation *Collation     // Specifies a collation
	Hint      interface{}    // The index to use
	Limit     *int64         // The maximum number of documents to count
	MaxTime   *time.Duration // The maximum amount of time to allow the operation to run
	Skip      *int64         // The number of documents to skip before counting
}

CountOptions represents all possible options to the Count() function.

func Count

func Count() *CountOptions

Count returns a pointer to a new CountOptions

func MergeCountOptions

func MergeCountOptions(opts ...*CountOptions) *CountOptions

MergeCountOptions combines the argued CountOptions into a single CountOptions in a last-one-wins fashion

func (*CountOptions) SetCollation

func (co *CountOptions) SetCollation(c *Collation) *CountOptions

SetCollation specifies a collation Valid for server versions >= 3.4

func (*CountOptions) SetHint

func (co *CountOptions) SetHint(h interface{}) *CountOptions

SetHint specifies the index to use

func (*CountOptions) SetLimit

func (co *CountOptions) SetLimit(i int64) *CountOptions

SetLimit specifies the maximum number of documents to count

func (*CountOptions) SetMaxTime

func (co *CountOptions) SetMaxTime(d time.Duration) *CountOptions

SetMaxTime specifies the maximum amount of time to allow the operation to run

func (*CountOptions) SetSkip

func (co *CountOptions) SetSkip(i int64) *CountOptions

SetSkip specifies the number of documents to skip before counting

type CreateIndexesOptions

type CreateIndexesOptions struct {
	MaxTime *time.Duration // The maximum amount of time to allow the query to run.
}

CreateIndexesOptions represents all possible options for the CreateOne() and CreateMany() functions.

func CreateIndexes

func CreateIndexes() *CreateIndexesOptions

CreateIndexes creates a new CreateIndexesOptions instance.

func MergeCreateIndexesOptions

func MergeCreateIndexesOptions(opts ...*CreateIndexesOptions) *CreateIndexesOptions

MergeCreateIndexesOptions combines the given *CreateIndexesOptions into a single *CreateIndexesOptions in a last one wins fashion.

func (*CreateIndexesOptions) SetMaxTime

SetMaxTime specifies the maximum amount of time to allow the query to run.

type Credential

type Credential struct {
	AuthMechanism           string
	AuthMechanismProperties map[string]string
	AuthSource              string
	Username                string
	Password                string
	PasswordSet             bool
}

Credential can be used to provide authentication options when configuring a Client.

AuthMechanism: the mechanism to use for authentication. Supported values include "SCRAM-SHA-256", "SCRAM-SHA-1", "MONGODB-CR", "PLAIN", "GSSAPI", and "MONGODB-X509". This can also be set through the "authMechanism" URI option. (e.g. "authMechanism=PLAIN"). For more information, see https://docs.mongodb.com/manual/core/authentication-mechanisms/.

AuthMechanismProperties can be used to specify additional configuration options for certain mechanisms. They can also be set through the "authMechanismProperites" URI option (e.g. "authMechanismProperties=SERVICE_NAME:service,CANONICALIZE_HOST_NAME:true"). Supported properties are:

1. SERVICE_NAME: The service name to use for GSSAPI authentication. The default is "mongodb".

2. CANONICALIZE_HOST_NAME: If "true", the driver will canonicalize the host name for GSSAPI authentication. The default is "false".

3. SERVICE_REALM: The service realm for GSSAPI authentication.

4. SERVICE_HOST: The host name to use for GSSAPI authentication. This should be specified if the host name to use for authentication is different than the one given for Client construction.

The SERVICE_HOST and CANONICALIZE_HOST_NAME properties must not be used at the same time on Linux and Darwin systems.

AuthSource: the name of the database to use for authentication. This defaults to "$external" for MONGODB-X509, GSSAPI, and PLAIN and "admin" for all other mechanisms. This can also be set through the "authSource" URI option (e.g. "authSource=otherDb").

Username: the username for authentication. This can also be set through the URI as a username:password pair before the first @ character. For example, a URI for user "user", password "pwd", and host "localhost:27017" would be "mongodb://user:pwd@localhost:27017". This is optional for X509 authentication and will be extracted from the client certificate if not specified.

Password: the password for authentication. This must not be specified for X509 and is optional for GSSAPI authentication.

PasswordSet specifies if the password is actually set, since an empty password is a valid password.

type CursorType

type CursorType int8

CursorType specifies whether a cursor should close when the last data is retrieved. See NonTailable, Tailable, and TailableAwait.

const (
	// NonTailable specifies that a cursor should close after retrieving the last data.
	NonTailable CursorType = iota
	// Tailable specifies that a cursor should not close when the last data is retrieved and can be resumed later.
	Tailable
	// TailableAwait specifies that a cursor should not close when the last data is retrieved and
	// that it should block for a certain amount of time for new data before returning no data.
	TailableAwait
)

type DataKeyOptions added in v1.2.0

type DataKeyOptions struct {
	MasterKey   interface{}
	KeyAltNames []string
}

DataKeyOptions represents all possible options used to create a new data key.

func DataKey added in v1.2.0

func DataKey() *DataKeyOptions

DataKey creates a new DataKeyOptions instance.

func MergeDataKeyOptions added in v1.2.0

func MergeDataKeyOptions(opts ...*DataKeyOptions) *DataKeyOptions

MergeDataKeyOptions combines the argued DataKeyOptions in a last-one wins fashion.

func (*DataKeyOptions) SetKeyAltNames added in v1.2.0

func (dk *DataKeyOptions) SetKeyAltNames(keyAltNames []string) *DataKeyOptions

SetKeyAltNames specifies an optional list of string alternate names used to reference a key. If a key is created' with alternate names, encryption may refer to the key by a unique alternate name instead of by _id.

func (*DataKeyOptions) SetMasterKey added in v1.2.0

func (dk *DataKeyOptions) SetMasterKey(masterKey interface{}) *DataKeyOptions

SetMasterKey specifies a KMS-specific key used to encrypt the new data key.

If being used with the AWS KMS provider, this option is required and must be a document with the following format: {region: string, key: string}.

If being used with a local KMS provider, this option is not applicable and should not be specified.

type DatabaseOptions

type DatabaseOptions struct {
	ReadConcern    *readconcern.ReadConcern   // The read concern for operations in the database.
	WriteConcern   *writeconcern.WriteConcern // The write concern for operations in the database.
	ReadPreference *readpref.ReadPref         // The read preference for operations in the database.
	Registry       *bsoncodec.Registry        // The registry to be used to construct BSON encoders and decoders for the database.
}

DatabaseOptions represent all possible options to configure a Database.

func Database

func Database() *DatabaseOptions

Database creates a new DatabaseOptions instance

func MergeDatabaseOptions

func MergeDatabaseOptions(opts ...*DatabaseOptions) *DatabaseOptions

MergeDatabaseOptions combines the *DatabaseOptions arguments into a single *DatabaseOptions in a last one wins fashion.

func (*DatabaseOptions) SetReadConcern

func (d *DatabaseOptions) SetReadConcern(rc *readconcern.ReadConcern) *DatabaseOptions

SetReadConcern sets the read concern for the database.

func (*DatabaseOptions) SetReadPreference

func (d *DatabaseOptions) SetReadPreference(rp *readpref.ReadPref) *DatabaseOptions

SetReadPreference sets the read preference for the database.

func (*DatabaseOptions) SetRegistry

func (d *DatabaseOptions) SetRegistry(r *bsoncodec.Registry) *DatabaseOptions

SetRegistry sets the bsoncodec Registry for the database.

func (*DatabaseOptions) SetWriteConcern

func (d *DatabaseOptions) SetWriteConcern(wc *writeconcern.WriteConcern) *DatabaseOptions

SetWriteConcern sets the write concern for the database.

type DeleteOptions

type DeleteOptions struct {
	Collation *Collation // Specifies a collation
}

DeleteOptions represents all possible options to the DeleteOne() and DeleteMany() functions.

func Delete

func Delete() *DeleteOptions

Delete returns a pointer to a new DeleteOptions

func MergeDeleteOptions

func MergeDeleteOptions(opts ...*DeleteOptions) *DeleteOptions

MergeDeleteOptions combines the argued DeleteOptions into a single DeleteOptions in a last-one-wins fashion

func (*DeleteOptions) SetCollation

func (do *DeleteOptions) SetCollation(c *Collation) *DeleteOptions

SetCollation specifies a collation Valid for servers >= 3.4.

type DistinctOptions

type DistinctOptions struct {
	Collation *Collation     // Specifies a collation
	MaxTime   *time.Duration // The maximum amount of time to allow the operation to run
}

DistinctOptions represents all possible options to the Distinct() function.

func Distinct

func Distinct() *DistinctOptions

Distinct returns a pointer to a new DistinctOptions

func MergeDistinctOptions

func MergeDistinctOptions(opts ...*DistinctOptions) *DistinctOptions

MergeDistinctOptions combines the argued DistinctOptions into a single DistinctOptions in a last-one-wins fashion

func (*DistinctOptions) SetCollation

func (do *DistinctOptions) SetCollation(c *Collation) *DistinctOptions

SetCollation specifies a collation Valid for server versions >= 3.4

func (*DistinctOptions) SetMaxTime

func (do *DistinctOptions) SetMaxTime(d time.Duration) *DistinctOptions

SetMaxTime specifies the maximum amount of time to allow the operation to run

type DropIndexesOptions

type DropIndexesOptions struct {
	MaxTime *time.Duration
}

DropIndexesOptions represents all possible options for the DropIndexes() function.

func DropIndexes

func DropIndexes() *DropIndexesOptions

DropIndexes creates a new DropIndexesOptions instance.

func MergeDropIndexesOptions

func MergeDropIndexesOptions(opts ...*DropIndexesOptions) *DropIndexesOptions

MergeDropIndexesOptions combines the given *DropIndexesOptions into a single *DropIndexesOptions in a last one wins fashion.

func (*DropIndexesOptions) SetMaxTime

func (d *DropIndexesOptions) SetMaxTime(duration time.Duration) *DropIndexesOptions

SetMaxTime specifies the maximum amount of time to allow the query to run.

type EncryptOptions added in v1.2.0

type EncryptOptions struct {
	KeyID      *primitive.Binary
	KeyAltName *string
	Algorithm  string
}

EncryptOptions represents options to explicitly encrypt a value.

func Encrypt added in v1.2.0

func Encrypt() *EncryptOptions

Encrypt creates a new EncryptOptions instance.

func MergeEncryptOptions added in v1.2.0

func MergeEncryptOptions(opts ...*EncryptOptions) *EncryptOptions

MergeEncryptOptions combines the argued EncryptOptions in a last-one wins fashion.

func (*EncryptOptions) SetAlgorithm added in v1.2.0

func (e *EncryptOptions) SetAlgorithm(algorithm string) *EncryptOptions

SetAlgorithm specifies an algorithm to use for encryption. This should be AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic or AEAD_AES_256_CBC_HMAC_SHA_512-Random. This is required.

func (*EncryptOptions) SetKeyAltName added in v1.2.0

func (e *EncryptOptions) SetKeyAltName(keyAltName string) *EncryptOptions

SetKeyAltName identifies a key vault document by 'keyAltName'.

func (*EncryptOptions) SetKeyID added in v1.2.0

func (e *EncryptOptions) SetKeyID(keyID primitive.Binary) *EncryptOptions

SetKeyID specifies an _id of a data key. This should be a UUID (a primitive.Binary with subtype 4).

type EstimatedDocumentCountOptions

type EstimatedDocumentCountOptions struct {
	MaxTime *time.Duration // The maximum amount of time to allow the operation to run
}

EstimatedDocumentCountOptions represents all possible options to the EstimatedDocumentCount() function.

func EstimatedDocumentCount

func EstimatedDocumentCount() *EstimatedDocumentCountOptions

EstimatedDocumentCount returns a pointer to a new EstimatedDocumentCountOptions

func MergeEstimatedDocumentCountOptions

func MergeEstimatedDocumentCountOptions(opts ...*EstimatedDocumentCountOptions) *EstimatedDocumentCountOptions

MergeEstimatedDocumentCountOptions combines the given *EstimatedDocumentCountOptions into a single *EstimatedDocumentCountOptions in a last one wins fashion.

func (*EstimatedDocumentCountOptions) SetMaxTime

SetMaxTime specifies the maximum amount of time to allow the operation to run

type FindOneAndDeleteOptions

type FindOneAndDeleteOptions struct {
	Collation  *Collation     // Specifies a collation to be used
	MaxTime    *time.Duration // Specifies the maximum amount of time to allow the query to run.
	Projection interface{}    // Limits the fields returned for all documents.
	Sort       interface{}    // Specifies the order in which to return results.
}

FindOneAndDeleteOptions represent all possible options to the FindOneAndDelete() function.

func FindOneAndDelete

func FindOneAndDelete() *FindOneAndDeleteOptions

FindOneAndDelete creates a new FindOneAndDeleteOptions instance.

func MergeFindOneAndDeleteOptions

func MergeFindOneAndDeleteOptions(opts ...*FindOneAndDeleteOptions) *FindOneAndDeleteOptions

MergeFindOneAndDeleteOptions combines the argued FindOneAndDeleteOptions into a single FindOneAndDeleteOptions in a last-one-wins fashion

func (*FindOneAndDeleteOptions) SetCollation

func (f *FindOneAndDeleteOptions) SetCollation(collation *Collation) *FindOneAndDeleteOptions

SetCollation specifies a Collation to use for the Find operation. Valid for server versions >= 3.4

func (*FindOneAndDeleteOptions) SetMaxTime

SetMaxTime specifies the max time to allow the query to run.

func (*FindOneAndDeleteOptions) SetProjection

func (f *FindOneAndDeleteOptions) SetProjection(projection interface{}) *FindOneAndDeleteOptions

SetProjection adds an option to limit the fields returned for all documents.

func (*FindOneAndDeleteOptions) SetSort

func (f *FindOneAndDeleteOptions) SetSort(sort interface{}) *FindOneAndDeleteOptions

SetSort specifies the order in which to return documents.

type FindOneAndReplaceOptions

type FindOneAndReplaceOptions struct {
	BypassDocumentValidation *bool           // If true, allows the write to opt out of document-level validation.
	Collation                *Collation      // Specifies a collation to be used
	MaxTime                  *time.Duration  // Specifies the maximum amount of time to allow the query to run.
	Projection               interface{}     // Limits the fields returned for all documents.
	ReturnDocument           *ReturnDocument // Specifies whether the original or updated document should be returned.
	Sort                     interface{}     // Specifies the order in which to return results.
	Upsert                   *bool           // If true, creates a a new document if no document matches the query.
}

FindOneAndReplaceOptions represent all possible options to the FindOneAndReplace() function.

func FindOneAndReplace

func FindOneAndReplace() *FindOneAndReplaceOptions

FindOneAndReplace creates a new FindOneAndReplaceOptions instance.

func MergeFindOneAndReplaceOptions

func MergeFindOneAndReplaceOptions(opts ...*FindOneAndReplaceOptions) *FindOneAndReplaceOptions

MergeFindOneAndReplaceOptions combines the argued FindOneAndReplaceOptions into a single FindOneAndReplaceOptions in a last-one-wins fashion

func (*FindOneAndReplaceOptions) SetBypassDocumentValidation

func (f *FindOneAndReplaceOptions) SetBypassDocumentValidation(b bool) *FindOneAndReplaceOptions

SetBypassDocumentValidation specifies whether or not the write should opt out of document-level validation. Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

func (*FindOneAndReplaceOptions) SetCollation

func (f *FindOneAndReplaceOptions) SetCollation(collation *Collation) *FindOneAndReplaceOptions

SetCollation specifies a Collation to use for the Find operation.

func (*FindOneAndReplaceOptions) SetMaxTime

SetMaxTime specifies the max time to allow the query to run.

func (*FindOneAndReplaceOptions) SetProjection

func (f *FindOneAndReplaceOptions) SetProjection(projection interface{}) *FindOneAndReplaceOptions

SetProjection adds an option to limit the fields returned for all documents.

func (*FindOneAndReplaceOptions) SetReturnDocument

SetReturnDocument specifies whether the original or updated document should be returned. If set to Before, the original document will be returned. If set to After, the updated document will be returned.

func (*FindOneAndReplaceOptions) SetSort

func (f *FindOneAndReplaceOptions) SetSort(sort interface{}) *FindOneAndReplaceOptions

SetSort specifies the order in which to return documents.

func (*FindOneAndReplaceOptions) SetUpsert

SetUpsert specifies if a new document should be created if no document matches the query.

type FindOneAndUpdateOptions

type FindOneAndUpdateOptions struct {
	ArrayFilters             *ArrayFilters   // A set of filters specifying to which array elements an update should apply.
	BypassDocumentValidation *bool           // If true, allows the write to opt out of document-level validation.
	Collation                *Collation      // Specifies a collation to be used
	MaxTime                  *time.Duration  // Specifies the maximum amount of time to allow the query to run.
	Projection               interface{}     // Limits the fields returned for all documents.
	ReturnDocument           *ReturnDocument // Specifies whether the original or updated document should be returned.
	Sort                     interface{}     // Specifies the order in which to return results.
	Upsert                   *bool           // If true, creates a a new document if no document matches the query.
}

FindOneAndUpdateOptions represent all possible options to the FindOneAndUpdate() function.

func FindOneAndUpdate

func FindOneAndUpdate() *FindOneAndUpdateOptions

FindOneAndUpdate creates a new FindOneAndUpdateOptions instance.

func MergeFindOneAndUpdateOptions

func MergeFindOneAndUpdateOptions(opts ...*FindOneAndUpdateOptions) *FindOneAndUpdateOptions

MergeFindOneAndUpdateOptions combines the argued FindOneAndUpdateOptions into a single FindOneAndUpdateOptions in a last-one-wins fashion

func (*FindOneAndUpdateOptions) SetArrayFilters

func (f *FindOneAndUpdateOptions) SetArrayFilters(filters ArrayFilters) *FindOneAndUpdateOptions

SetArrayFilters specifies a set of filters, which

func (*FindOneAndUpdateOptions) SetBypassDocumentValidation

func (f *FindOneAndUpdateOptions) SetBypassDocumentValidation(b bool) *FindOneAndUpdateOptions

SetBypassDocumentValidation sets filters that specify to which array elements an update should apply.

func (*FindOneAndUpdateOptions) SetCollation

func (f *FindOneAndUpdateOptions) SetCollation(collation *Collation) *FindOneAndUpdateOptions

SetCollation specifies a Collation to use for the Find operation.

func (*FindOneAndUpdateOptions) SetMaxTime

SetMaxTime specifies the max time to allow the query to run.

func (*FindOneAndUpdateOptions) SetProjection

func (f *FindOneAndUpdateOptions) SetProjection(projection interface{}) *FindOneAndUpdateOptions

SetProjection adds an option to limit the fields returned for all documents.

func (*FindOneAndUpdateOptions) SetReturnDocument

SetReturnDocument specifies whether the original or updated document should be returned. If set to Before, the original document will be returned. If set to After, the updated document will be returned.

func (*FindOneAndUpdateOptions) SetSort

func (f *FindOneAndUpdateOptions) SetSort(sort interface{}) *FindOneAndUpdateOptions

SetSort specifies the order in which to return documents.

func (*FindOneAndUpdateOptions) SetUpsert

SetUpsert specifies if a new document should be created if no document matches the query.

type FindOneOptions

type FindOneOptions struct {
	AllowPartialResults *bool          // If true, allows partial results to be returned if some shards are down.
	BatchSize           *int32         // Specifies the number of documents to return in every batch.
	Collation           *Collation     // Specifies a collation to be used
	Comment             *string        // Specifies a string to help trace the operation through the database.
	CursorType          *CursorType    // Specifies the type of cursor to use
	Hint                interface{}    // Specifies the index to use.
	Max                 interface{}    // Sets an exclusive upper bound for a specific index
	MaxAwaitTime        *time.Duration // Specifies the maximum amount of time for the server to wait on new documents.
	MaxTime             *time.Duration // Specifies the maximum amount of time to allow the query to run.
	Min                 interface{}    // Specifies the inclusive lower bound for a specific index.
	NoCursorTimeout     *bool          // If true, prevents cursors from timing out after an inactivity period.
	OplogReplay         *bool          // Adds an option for internal use only and should not be set.
	Projection          interface{}    // Limits the fields returned for all documents.
	ReturnKey           *bool          // If true, only returns index keys for all result documents.
	ShowRecordID        *bool          // If true, a $recordId field with the record identifier will be added to the returned documents.
	Skip                *int64         // Specifies the number of documents to skip before returning
	Snapshot            *bool          // If true, prevents the cursor from returning a document more than once because of an intervening write operation.
	Sort                interface{}    // Specifies the order in which to return results.
}

FindOneOptions represent all possible options to the FindOne() function.

func FindOne

func FindOne() *FindOneOptions

FindOne creates a new FindOneOptions instance.

func MergeFindOneOptions

func MergeFindOneOptions(opts ...*FindOneOptions) *FindOneOptions

MergeFindOneOptions combines the argued FindOneOptions into a single FindOneOptions in a last-one-wins fashion

func (*FindOneOptions) SetAllowPartialResults

func (f *FindOneOptions) SetAllowPartialResults(b bool) *FindOneOptions

SetAllowPartialResults sets whether partial results can be returned if some shards are down.

func (*FindOneOptions) SetBatchSize

func (f *FindOneOptions) SetBatchSize(i int32) *FindOneOptions

SetBatchSize sets the number of documents to return in each batch.

func (*FindOneOptions) SetCollation

func (f *FindOneOptions) SetCollation(collation *Collation) *FindOneOptions

SetCollation specifies a Collation to use for the Find operation.

func (*FindOneOptions) SetComment

func (f *FindOneOptions) SetComment(comment string) *FindOneOptions

SetComment specifies a string to help trace the operation through the database.

func (*FindOneOptions) SetCursorType

func (f *FindOneOptions) SetCursorType(ct CursorType) *FindOneOptions

SetCursorType specifes the type of cursor to use.

func (*FindOneOptions) SetHint

func (f *FindOneOptions) SetHint(hint interface{}) *FindOneOptions

SetHint specifies the index to use.

func (*FindOneOptions) SetMax

func (f *FindOneOptions) SetMax(max interface{}) *FindOneOptions

SetMax specifies an exclusive upper bound for a specific index.

func (*FindOneOptions) SetMaxAwaitTime

func (f *FindOneOptions) SetMaxAwaitTime(d time.Duration) *FindOneOptions

SetMaxAwaitTime specifies the max amount of time for the server to wait on new documents. For server versions < 3.2, this option is ignored.

func (*FindOneOptions) SetMaxTime

func (f *FindOneOptions) SetMaxTime(d time.Duration) *FindOneOptions

SetMaxTime specifies the max time to allow the query to run.

func (*FindOneOptions) SetMin

func (f *FindOneOptions) SetMin(min interface{}) *FindOneOptions

SetMin specifies the inclusive lower bound for a specific index.

func (*FindOneOptions) SetNoCursorTimeout

func (f *FindOneOptions) SetNoCursorTimeout(b bool) *FindOneOptions

SetNoCursorTimeout specifies whether or not cursors should time out after a period of inactivity.

func (*FindOneOptions) SetOplogReplay

func (f *FindOneOptions) SetOplogReplay(b bool) *FindOneOptions

SetOplogReplay adds an option for internal use only and should not be set.

func (*FindOneOptions) SetProjection

func (f *FindOneOptions) SetProjection(projection interface{}) *FindOneOptions

SetProjection adds an option to limit the fields returned for all documents.

func (*FindOneOptions) SetReturnKey

func (f *FindOneOptions) SetReturnKey(b bool) *FindOneOptions

SetReturnKey adds an option to only return index keys for all result documents.

func (*FindOneOptions) SetShowRecordID

func (f *FindOneOptions) SetShowRecordID(b bool) *FindOneOptions

SetShowRecordID adds an option to determine whether to return the record identifier for each document. If true, a $recordId field will be added to each returned document.

func (*FindOneOptions) SetSkip

func (f *FindOneOptions) SetSkip(i int64) *FindOneOptions

SetSkip specifies the number of documents to skip before returning.

func (*FindOneOptions) SetSnapshot

func (f *FindOneOptions) SetSnapshot(b bool) *FindOneOptions

SetSnapshot prevents the cursor from returning a document more than once because of an intervening write operation.

func (*FindOneOptions) SetSort

func (f *FindOneOptions) SetSort(sort interface{}) *FindOneOptions

SetSort specifies the order in which to return documents.

type FindOptions

type FindOptions struct {
	AllowPartialResults *bool          // If true, allows partial results to be returned if some shards are down.
	BatchSize           *int32         // Specifies the number of documents to return in every batch.
	Collation           *Collation     // Specifies a collation to be used
	Comment             *string        // Specifies a string to help trace the operation through the database.
	CursorType          *CursorType    // Specifies the type of cursor to use
	Hint                interface{}    // Specifies the index to use.
	Limit               *int64         // Sets a limit on the number of results to return.
	Max                 interface{}    // Sets an exclusive upper bound for a specific index
	MaxAwaitTime        *time.Duration // Specifies the maximum amount of time for the server to wait on new documents.
	MaxTime             *time.Duration // Specifies the maximum amount of time to allow the query to run.
	Min                 interface{}    // Specifies the inclusive lower bound for a specific index.
	NoCursorTimeout     *bool          // If true, prevents cursors from timing out after an inactivity period.
	OplogReplay         *bool          // Adds an option for internal use only and should not be set.
	Projection          interface{}    // Limits the fields returned for all documents.
	ReturnKey           *bool          // If true, only returns index keys for all result documents.
	ShowRecordID        *bool          // If true, a $recordId field with the record identifier will be added to the returned documents.
	Skip                *int64         // Specifies the number of documents to skip before returning
	Snapshot            *bool          // If true, prevents the cursor from returning a document more than once because of an intervening write operation.
	Sort                interface{}    // Specifies the order in which to return results.
}

FindOptions represent all possible options to the Find() function.

func Find

func Find() *FindOptions

Find creates a new FindOptions instance.

func MergeFindOptions

func MergeFindOptions(opts ...*FindOptions) *FindOptions

MergeFindOptions combines the argued FindOptions into a single FindOptions in a last-one-wins fashion

func (*FindOptions) SetAllowPartialResults

func (f *FindOptions) SetAllowPartialResults(b bool) *FindOptions

SetAllowPartialResults sets whether partial results can be returned if some shards are down. For server versions < 3.2, this defaults to false.

func (*FindOptions) SetBatchSize

func (f *FindOptions) SetBatchSize(i int32) *FindOptions

SetBatchSize sets the number of documents to return in each batch.

func (*FindOptions) SetCollation

func (f *FindOptions) SetCollation(collation *Collation) *FindOptions

SetCollation specifies a Collation to use for the Find operation. Valid for server versions >= 3.4

func (*FindOptions) SetComment

func (f *FindOptions) SetComment(comment string) *FindOptions

SetComment specifies a string to help trace the operation through the database.

func (*FindOptions) SetCursorType

func (f *FindOptions) SetCursorType(ct CursorType) *FindOptions

SetCursorType specifes the type of cursor to use.

func (*FindOptions) SetHint

func (f *FindOptions) SetHint(hint interface{}) *FindOptions

SetHint specifies the index to use.

func (*FindOptions) SetLimit

func (f *FindOptions) SetLimit(i int64) *FindOptions

SetLimit specifies a limit on the number of results. A negative limit implies that only 1 batch should be returned.

func (*FindOptions) SetMax

func (f *FindOptions) SetMax(max interface{}) *FindOptions

SetMax specifies an exclusive upper bound for a specific index.

func (*FindOptions) SetMaxAwaitTime

func (f *FindOptions) SetMaxAwaitTime(d time.Duration) *FindOptions

SetMaxAwaitTime specifies the max amount of time for the server to wait on new documents. If the cursor type is not TailableAwait, this option is ignored. For server versions < 3.2, this option is ignored.

func (*FindOptions) SetMaxTime

func (f *FindOptions) SetMaxTime(d time.Duration) *FindOptions

SetMaxTime specifies the max time to allow the query to run.

func (*FindOptions) SetMin

func (f *FindOptions) SetMin(min interface{}) *FindOptions

SetMin specifies the inclusive lower bound for a specific index.

func (*FindOptions) SetNoCursorTimeout

func (f *FindOptions) SetNoCursorTimeout(b bool) *FindOptions

SetNoCursorTimeout specifies whether or not cursors should time out after a period of inactivity. For server versions < 3.2, this defaults to false.

func (*FindOptions) SetOplogReplay

func (f *FindOptions) SetOplogReplay(b bool) *FindOptions

SetOplogReplay adds an option for internal use only and should not be set. For server versions < 3.2, this defaults to false.

func (*FindOptions) SetProjection

func (f *FindOptions) SetProjection(projection interface{}) *FindOptions

SetProjection adds an option to limit the fields returned for all documents.

func (*FindOptions) SetReturnKey

func (f *FindOptions) SetReturnKey(b bool) *FindOptions

SetReturnKey adds an option to only return index keys for all result documents.

func (*FindOptions) SetShowRecordID

func (f *FindOptions) SetShowRecordID(b bool) *FindOptions

SetShowRecordID adds an option to determine whether to return the record identifier for each document. If true, a $recordId field will be added to each returned document.

func (*FindOptions) SetSkip

func (f *FindOptions) SetSkip(i int64) *FindOptions

SetSkip specifies the number of documents to skip before returning. For server versions < 3.2, this defaults to 0.

func (*FindOptions) SetSnapshot

func (f *FindOptions) SetSnapshot(b bool) *FindOptions

SetSnapshot prevents the cursor from returning a document more than once because of an intervening write operation.

func (*FindOptions) SetSort

func (f *FindOptions) SetSort(sort interface{}) *FindOptions

SetSort specifies the order in which to return documents.

type FullDocument

type FullDocument string

FullDocument specifies whether a change stream should include a copy of the entire document that was changed from some time after the change occurred.

const (
	// Default does not include a document copy
	Default FullDocument = "default"
	// UpdateLookup includes a delta describing the changes to the document and a copy of the entire document that
	// was changed
	UpdateLookup FullDocument = "updateLookup"
)

type GridFSFindOptions

type GridFSFindOptions struct {
	BatchSize       *int32
	Limit           *int32
	MaxTime         *time.Duration
	NoCursorTimeout *bool
	Skip            *int32
	Sort            interface{}
}

GridFSFindOptions represents all options for a GridFS find operation.

func GridFSFind

func GridFSFind() *GridFSFindOptions

GridFSFind creates a new GridFSFindOptions instance.

func MergeGridFSFindOptions

func MergeGridFSFindOptions(opts ...*GridFSFindOptions) *GridFSFindOptions

MergeGridFSFindOptions combines the argued GridFSFindOptions into a single GridFSFindOptions in a last-one-wins fashion

func (*GridFSFindOptions) SetBatchSize

func (f *GridFSFindOptions) SetBatchSize(i int32) *GridFSFindOptions

SetBatchSize sets the number of documents to return in each batch.

func (*GridFSFindOptions) SetLimit

func (f *GridFSFindOptions) SetLimit(i int32) *GridFSFindOptions

SetLimit specifies a limit on the number of results. A negative limit implies that only 1 batch should be returned.

func (*GridFSFindOptions) SetMaxTime

SetMaxTime specifies the max time to allow the query to run.

func (*GridFSFindOptions) SetNoCursorTimeout

func (f *GridFSFindOptions) SetNoCursorTimeout(b bool) *GridFSFindOptions

SetNoCursorTimeout specifies whether or not cursors should time out after a period of inactivity.

func (*GridFSFindOptions) SetSkip

func (f *GridFSFindOptions) SetSkip(i int32) *GridFSFindOptions

SetSkip specifies the number of documents to skip before returning.

func (*GridFSFindOptions) SetSort

func (f *GridFSFindOptions) SetSort(sort interface{}) *GridFSFindOptions

SetSort specifies the order in which to return documents.

type IndexOptions

type IndexOptions struct {
	Background              *bool
	ExpireAfterSeconds      *int32
	Name                    *string
	Sparse                  *bool
	StorageEngine           interface{}
	Unique                  *bool
	Version                 *int32
	DefaultLanguage         *string
	LanguageOverride        *string
	TextVersion             *int32
	Weights                 interface{}
	SphereVersion           *int32
	Bits                    *int32
	Max                     *float64
	Min                     *float64
	BucketSize              *int32
	PartialFilterExpression interface{}
	Collation               *Collation
	WildcardProjection      interface{}
}

IndexOptions represents all possible options to configure a new index.

func Index

func Index() *IndexOptions

Index creates a new *IndexOptions

func MergeIndexOptions

func MergeIndexOptions(opts ...*IndexOptions) *IndexOptions

MergeIndexOptions combines the given *IndexOptions into a single *IndexOptions in a last one wins fashion.

func (*IndexOptions) SetBackground

func (i *IndexOptions) SetBackground(background bool) *IndexOptions

SetBackground sets the background option. If true, the server will create the index in the background and not block other tasks

func (*IndexOptions) SetBits

func (i *IndexOptions) SetBits(bits int32) *IndexOptions

SetBits specifies the precision of the stored geo hash in the 2d index, from 1 to 32.

func (*IndexOptions) SetBucketSize

func (i *IndexOptions) SetBucketSize(bucketSize int32) *IndexOptions

SetBucketSize specifies number of units within which to group the location values in a geo haystack index.

func (*IndexOptions) SetCollation

func (i *IndexOptions) SetCollation(collation *Collation) *IndexOptions

SetCollation specifies a Collation to use for the operation. Valid for server versions >= 3.4

func (*IndexOptions) SetDefaultLanguage

func (i *IndexOptions) SetDefaultLanguage(language string) *IndexOptions

SetDefaultLanguage specifies the default language for text indexes. If not set, this will default to english.

func (*IndexOptions) SetExpireAfterSeconds

func (i *IndexOptions) SetExpireAfterSeconds(seconds int32) *IndexOptions

SetExpireAfterSeconds specifies the number of seconds for a document to remain in a collection.

func (*IndexOptions) SetLanguageOverride

func (i *IndexOptions) SetLanguageOverride(override string) *IndexOptions

SetLanguageOverride specifies the field in the document to override the language.

func (*IndexOptions) SetMax

func (i *IndexOptions) SetMax(max float64) *IndexOptions

SetMax specifies the maximum boundary for latitude and longitude in the 2d index.

func (*IndexOptions) SetMin

func (i *IndexOptions) SetMin(min float64) *IndexOptions

SetMin specifies the minimum boundary for latitude and longitude in the 2d index.

func (*IndexOptions) SetName

func (i *IndexOptions) SetName(name string) *IndexOptions

SetName specifies a name for the index. If not set, a name will be generated in the format "[field]_[direction]". If multiple indexes are created for the same key pattern with different collations, a name must be provided to avoid ambiguity.

func (*IndexOptions) SetPartialFilterExpression

func (i *IndexOptions) SetPartialFilterExpression(expression interface{}) *IndexOptions

SetPartialFilterExpression specifies a filter for use in a partial index. Only documents that match the filter expression are included in the index.

func (*IndexOptions) SetSparse

func (i *IndexOptions) SetSparse(sparse bool) *IndexOptions

SetSparse sets the sparse option. If true, the index will only reference documents with the specified field in the index.

func (*IndexOptions) SetSphereVersion

func (i *IndexOptions) SetSphereVersion(version int32) *IndexOptions

SetSphereVersion specifies the 2dsphere index version number. MongoDB version 2.4 can only support version 1. MongoDB versions 2.6 and higher can support versions 1 or 2.

func (*IndexOptions) SetStorageEngine

func (i *IndexOptions) SetStorageEngine(engine interface{}) *IndexOptions

SetStorageEngine specifies the storage engine to use. Valid for server versions >= 3.0

func (*IndexOptions) SetTextVersion

func (i *IndexOptions) SetTextVersion(version int32) *IndexOptions

SetTextVersion specifies the text index version number. MongoDB version 2.4 can only support version 1. MongoDB versions 2.6 and higher can support versions 1 or 2.

func (*IndexOptions) SetUnique

func (i *IndexOptions) SetUnique(unique bool) *IndexOptions

SetUnique forces the index to be unique.

func (*IndexOptions) SetVersion

func (i *IndexOptions) SetVersion(version int32) *IndexOptions

SetVersion specifies the index version number, either 0 or 1.

func (*IndexOptions) SetWeights

func (i *IndexOptions) SetWeights(weights interface{}) *IndexOptions

SetWeights specifies fields in the index and their corresponding weight values.

func (*IndexOptions) SetWildcardProjection added in v1.1.0

func (i *IndexOptions) SetWildcardProjection(wildcardProjection interface{}) *IndexOptions

SetWildcardProjection specifies a wildcard projection for a wildcard index.

type InsertManyOptions

type InsertManyOptions struct {
	BypassDocumentValidation *bool // If true, allows the write to opt-out of document level validation
	Ordered                  *bool // If true, when an insert fails, return without performing the remaining inserts. Defaults to true.
}

InsertManyOptions represents all possible options to the InsertMany() function.

func InsertMany

func InsertMany() *InsertManyOptions

InsertMany returns a pointer to a new InsertManyOptions

func MergeInsertManyOptions

func MergeInsertManyOptions(opts ...*InsertManyOptions) *InsertManyOptions

MergeInsertManyOptions combines the argued InsertManyOptions into a single InsertManyOptions in a last-one-wins fashion

func (*InsertManyOptions) SetBypassDocumentValidation

func (imo *InsertManyOptions) SetBypassDocumentValidation(b bool) *InsertManyOptions

SetBypassDocumentValidation allows the write to opt-out of document level validation. Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

func (*InsertManyOptions) SetOrdered

func (imo *InsertManyOptions) SetOrdered(b bool) *InsertManyOptions

SetOrdered configures the ordered option. If true, when a write fails, the function will return without attempting remaining writes. Defaults to true.

type InsertOneOptions

type InsertOneOptions struct {
	BypassDocumentValidation *bool // If true, allows the write to opt-out of document level validation
}

InsertOneOptions represents all possible options to the InsertOne() function.

func InsertOne

func InsertOne() *InsertOneOptions

InsertOne returns a pointer to a new InsertOneOptions

func MergeInsertOneOptions

func MergeInsertOneOptions(opts ...*InsertOneOptions) *InsertOneOptions

MergeInsertOneOptions combines the argued InsertOneOptions into a single InsertOneOptions in a last-one-wins fashion

func (*InsertOneOptions) SetBypassDocumentValidation

func (ioo *InsertOneOptions) SetBypassDocumentValidation(b bool) *InsertOneOptions

SetBypassDocumentValidation allows the write to opt-out of document level validation. Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

type ListCollectionsOptions

type ListCollectionsOptions struct {
	NameOnly *bool // If true, only the collection names will be returned.
}

ListCollectionsOptions represents all possible options for a listCollections command.

func ListCollections

func ListCollections() *ListCollectionsOptions

ListCollections creates a new *ListCollectionsOptions

func MergeListCollectionsOptions

func MergeListCollectionsOptions(opts ...*ListCollectionsOptions) *ListCollectionsOptions

MergeListCollectionsOptions combines the given *ListCollectionsOptions into a single *ListCollectionsOptions in a last one wins fashion.

func (*ListCollectionsOptions) SetNameOnly

SetNameOnly specifies whether to return only the collection names.

type ListDatabasesOptions

type ListDatabasesOptions struct {
	NameOnly *bool // If true, only the database names will be returned.
}

ListDatabasesOptions represents all possible options for a listDatabases command.

func ListDatabases

func ListDatabases() *ListDatabasesOptions

ListDatabases creates a new *ListDatabasesOptions

func MergeListDatabasesOptions

func MergeListDatabasesOptions(opts ...*ListDatabasesOptions) *ListDatabasesOptions

MergeListDatabasesOptions combines the given *ListDatabasesOptions into a single *ListDatabasesOptions in a last one wins fashion.

func (*ListDatabasesOptions) SetNameOnly

func (ld *ListDatabasesOptions) SetNameOnly(b bool) *ListDatabasesOptions

SetNameOnly specifies whether to return only the database names.

type ListIndexesOptions

type ListIndexesOptions struct {
	BatchSize *int32
	MaxTime   *time.Duration
}

ListIndexesOptions represents all possible options for the ListIndexes() function.

func ListIndexes

func ListIndexes() *ListIndexesOptions

ListIndexes creates a new ListIndexesOptions instance.

func MergeListIndexesOptions

func MergeListIndexesOptions(opts ...*ListIndexesOptions) *ListIndexesOptions

MergeListIndexesOptions combines the given *ListIndexesOptions into a single *ListIndexesOptions in a last one wins fashion.

func (*ListIndexesOptions) SetBatchSize

func (l *ListIndexesOptions) SetBatchSize(i int32) *ListIndexesOptions

SetBatchSize specifies the number of documents to return in every batch.

func (*ListIndexesOptions) SetMaxTime

SetMaxTime specifies the maximum amount of time to allow the query to run.

type MarshalError

type MarshalError struct {
	Value interface{}
	Err   error
}

MarshalError is returned when attempting to transform a value into a document results in an error.

func (MarshalError) Error

func (me MarshalError) Error() string

Error implements the error interface.

type NameOptions

type NameOptions struct {
	Revision *int32 // Which revision (documents with the same filename and different uploadDate). Defaults to -1 (the most recent revision).
}

NameOptions represents all options that can be used for a GridFS download by name operation.

func GridFSName

func GridFSName() *NameOptions

GridFSName creates a new *NameOptions

func MergeNameOptions

func MergeNameOptions(opts ...*NameOptions) *NameOptions

MergeNameOptions combines the given *NameOptions into a single *NameOptions in a last one wins fashion.

func (*NameOptions) SetRevision

func (n *NameOptions) SetRevision(r int32) *NameOptions

SetRevision specifies which revision of the file to retrieve. Defaults to -1. * Revision numbers are defined as follows: * 0 = the original stored file * 1 = the first revision * 2 = the second revision * etc… * -2 = the second most recent revision * -1 = the most recent revision

type ReplaceOptions

type ReplaceOptions struct {
	BypassDocumentValidation *bool      // If true, allows the write to opt-out of document level validation
	Collation                *Collation // Specifies a collation
	Upsert                   *bool      // When true, creates a new document if no document matches the query
}

ReplaceOptions represents all possible options to the ReplaceOne() function.

func MergeReplaceOptions

func MergeReplaceOptions(opts ...*ReplaceOptions) *ReplaceOptions

MergeReplaceOptions combines the argued ReplaceOptions into a single ReplaceOptions in a last-one-wins fashion

func Replace

func Replace() *ReplaceOptions

Replace returns a pointer to a new ReplaceOptions

func (*ReplaceOptions) SetBypassDocumentValidation

func (ro *ReplaceOptions) SetBypassDocumentValidation(b bool) *ReplaceOptions

SetBypassDocumentValidation allows the write to opt-out of document level validation. Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

func (*ReplaceOptions) SetCollation

func (ro *ReplaceOptions) SetCollation(c *Collation) *ReplaceOptions

SetCollation specifies a collation. Valid for servers >= 3.4

func (*ReplaceOptions) SetUpsert

func (ro *ReplaceOptions) SetUpsert(b bool) *ReplaceOptions

SetUpsert allows the creation of a new document if not document matches the query

type ReturnDocument

type ReturnDocument int8

ReturnDocument specifies whether a findAndUpdate operation should return the document as it was before the update or as it is after the update.

const (
	// Before specifies that findAndUpdate should return the document as it was before the update.
	Before ReturnDocument = iota
	// After specifies that findAndUpdate should return the document as it is after the update.
	After
)

type RunCmdOptions

type RunCmdOptions struct {
	ReadPreference *readpref.ReadPref // The read preference for the operation.
}

RunCmdOptions represents all possible options for a runCommand operation.

func MergeRunCmdOptions

func MergeRunCmdOptions(opts ...*RunCmdOptions) *RunCmdOptions

MergeRunCmdOptions combines the given *RunCmdOptions into one *RunCmdOptions in a last one wins fashion.

func RunCmd

func RunCmd() *RunCmdOptions

RunCmd creates a new *RunCmdOptions

func (*RunCmdOptions) SetReadPreference

func (rc *RunCmdOptions) SetReadPreference(rp *readpref.ReadPref) *RunCmdOptions

SetReadPreference sets the read preference for the operation.

type SessionOptions

type SessionOptions struct {
	CausalConsistency     *bool                      // Specifies if reads should be causally consistent. Defaults to true.
	DefaultReadConcern    *readconcern.ReadConcern   // The default read concern for transactions started in the session.
	DefaultReadPreference *readpref.ReadPref         // The default read preference for transactions started in the session.
	DefaultWriteConcern   *writeconcern.WriteConcern // The default write concern for transactions started in the session.
	DefaultMaxCommitTime  *time.Duration             // The default max commit time for transactions started in the session.
}

SessionOptions represents all possible options for creating a new session.

func MergeSessionOptions

func MergeSessionOptions(opts ...*SessionOptions) *SessionOptions

MergeSessionOptions combines the given *SessionOptions into a single *SessionOptions in a last one wins fashion.

func Session

func Session() *SessionOptions

Session creates a new *SessionOptions

func (*SessionOptions) SetCausalConsistency

func (s *SessionOptions) SetCausalConsistency(b bool) *SessionOptions

SetCausalConsistency specifies if a session should be causally consistent. Defaults to true.

func (*SessionOptions) SetDefaultMaxCommitTime added in v1.1.0

func (s *SessionOptions) SetDefaultMaxCommitTime(mct *time.Duration) *SessionOptions

SetDefaultMaxCommitTime sets the default max commit time for transactions started in a session.

func (*SessionOptions) SetDefaultReadConcern

func (s *SessionOptions) SetDefaultReadConcern(rc *readconcern.ReadConcern) *SessionOptions

SetDefaultReadConcern sets the default read concern for transactions started in a session.

func (*SessionOptions) SetDefaultReadPreference

func (s *SessionOptions) SetDefaultReadPreference(rp *readpref.ReadPref) *SessionOptions

SetDefaultReadPreference sets the default read preference for transactions started in a session.

func (*SessionOptions) SetDefaultWriteConcern

func (s *SessionOptions) SetDefaultWriteConcern(wc *writeconcern.WriteConcern) *SessionOptions

SetDefaultWriteConcern sets the default write concern for transactions started in a session.

type TransactionOptions

type TransactionOptions struct {
	ReadConcern    *readconcern.ReadConcern   // The read concern for the transaction. Defaults to the session's read concern.
	ReadPreference *readpref.ReadPref         // The read preference for the transaction. Defaults to the session's read preference.
	WriteConcern   *writeconcern.WriteConcern // The write concern for the transaction. Defaults to the session's write concern.
	MaxCommitTime  *time.Duration             // The maximum amount of time to allow a single commitTransaction command to run.
}

TransactionOptions represents all possible options for starting a transaction.

func MergeTransactionOptions

func MergeTransactionOptions(opts ...*TransactionOptions) *TransactionOptions

MergeTransactionOptions combines the given *TransactionOptions into a single *TransactionOptions in a last one wins fashion.

func Transaction

func Transaction() *TransactionOptions

Transaction creates a new *TransactionOptions

func (*TransactionOptions) SetMaxCommitTime added in v1.1.0

func (t *TransactionOptions) SetMaxCommitTime(mct *time.Duration) *TransactionOptions

SetMaxCommitTime sets the max commit time for the transaction.

func (*TransactionOptions) SetReadConcern

SetReadConcern sets the read concern for the transaction.

func (*TransactionOptions) SetReadPreference

func (t *TransactionOptions) SetReadPreference(rp *readpref.ReadPref) *TransactionOptions

SetReadPreference sets the read preference for the transaction.

func (*TransactionOptions) SetWriteConcern

SetWriteConcern sets the write concern for the transaction.

type UpdateOptions

type UpdateOptions struct {
	ArrayFilters             *ArrayFilters // A set of filters specifying to which array elements an update should apply
	BypassDocumentValidation *bool         // If true, allows the write to opt-out of document level validation
	Collation                *Collation    // Specifies a collation
	Upsert                   *bool         // When true, creates a new document if no document matches the query
}

UpdateOptions represents all possible options to the UpdateOne() and UpdateMany() functions.

func MergeUpdateOptions

func MergeUpdateOptions(opts ...*UpdateOptions) *UpdateOptions

MergeUpdateOptions combines the argued UpdateOptions into a single UpdateOptions in a last-one-wins fashion

func Update

func Update() *UpdateOptions

Update returns a pointer to a new UpdateOptions

func (*UpdateOptions) SetArrayFilters

func (uo *UpdateOptions) SetArrayFilters(af ArrayFilters) *UpdateOptions

SetArrayFilters specifies a set of filters specifying to which array elements an update should apply Valid for server versions >= 3.6.

func (*UpdateOptions) SetBypassDocumentValidation

func (uo *UpdateOptions) SetBypassDocumentValidation(b bool) *UpdateOptions

SetBypassDocumentValidation allows the write to opt-out of document level validation. Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.

func (*UpdateOptions) SetCollation

func (uo *UpdateOptions) SetCollation(c *Collation) *UpdateOptions

SetCollation specifies a collation. Valid for server versions >= 3.4.

func (*UpdateOptions) SetUpsert

func (uo *UpdateOptions) SetUpsert(b bool) *UpdateOptions

SetUpsert allows the creation of a new document if not document matches the query

type UploadOptions

type UploadOptions struct {
	ChunkSizeBytes *int32              // Chunk size in bytes. Defaults to the chunk size of the bucket.
	Metadata       interface{}         // User data for the 'metadata' field of the files collection document.
	Registry       *bsoncodec.Registry // The registry to use for converting filters. Defaults to bson.DefaultRegistry.
}

UploadOptions represents all possible options for a GridFS upload operation. If a registry is nil, bson.DefaultRegistry will be used when converting the Metadata interface to BSON.

func GridFSUpload

func GridFSUpload() *UploadOptions

GridFSUpload creates a new *UploadOptions

func MergeUploadOptions

func MergeUploadOptions(opts ...*UploadOptions) *UploadOptions

MergeUploadOptions combines the given *UploadOptions into a single *UploadOptions. If the chunk size is not set in any of the given *UploadOptions, the resulting *UploadOptions will have chunk size 255KB.

func (*UploadOptions) SetChunkSizeBytes

func (u *UploadOptions) SetChunkSizeBytes(i int32) *UploadOptions

SetChunkSizeBytes sets the chunk size in bytes for the upload. Defaults to 255KB if not set.

func (*UploadOptions) SetMetadata

func (u *UploadOptions) SetMetadata(doc interface{}) *UploadOptions

SetMetadata specfies the metadata for the upload.

Jump to

Keyboard shortcuts

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