mongo-driver: go.mongodb.org/mongo-driver/mongo/options Index | Files

package options

import "go.mongodb.org/mongo-driver/mongo/options"

Index

Package Files

aggregateoptions.go autoencryptionoptions.go bulkwriteoptions.go changestreamoptions.go clientencryptionoptions.go clientoptions.go clientoptions_1_10.go collectionoptions.go countoptions.go createcollectionoptions.go datakeyoptions.go dboptions.go deleteoptions.go distinctoptions.go encryptoptions.go estimatedcountoptions.go findoptions.go gridfsoptions.go indexoptions.go insertoptions.go listcollectionsoptions.go listdatabasesoptions.go mongooptions.go replaceoptions.go runcmdoptions.go sessionoptions.go transactionoptions.go updateoptions.go

Variables

var DefaultCausalConsistency = true

DefaultCausalConsistency is the default value for the CausalConsistency option.

var DefaultChunkSize int32 = 255 * 1024

DefaultChunkSize is the default size of each file chunk in bytes (255 KiB).

var DefaultName = "fs"

DefaultName is the default name for a GridFS bucket.

var DefaultOrdered = true

DefaultOrdered is the default value for the Ordered option in BulkWriteOptions.

var DefaultRevision int32 = -1

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

type AggregateOptions Uses

type AggregateOptions struct {
    // If true, the operation can write to temporary files in the _tmp subdirectory of the database directory path on
    // the server. The default value is false.
    AllowDiskUse *bool

    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32

    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
    // This option is only valid for MongoDB versions >= 3.2 and is ignored for previous server versions.
    MaxAwaitTime *time.Duration

    // A string that will be included in server logs, profiling logs, and currentOp queries to help trace the operation.
    // The default is the empty string, which means that no comment will be included in the logs.
    Comment *string

    // The index to use for the aggregation. This should either be the index name as a string or the index specification
    // as a document. The hint does not apply to $lookup and $graphLookup aggregation stages. The default value is nil,
    // which means that no hint will be sent.
    Hint interface{}
}

AggregateOptions represents options that can be used to configure an Aggregate operation.

func Aggregate Uses

func Aggregate() *AggregateOptions

Aggregate creates a new AggregateOptions instance.

func MergeAggregateOptions Uses

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

MergeAggregateOptions combines the given AggregateOptions instances into a single AggregateOptions in a last-one-wins fashion.

func (*AggregateOptions) SetAllowDiskUse Uses

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

SetAllowDiskUse sets the value for the AllowDiskUse field.

func (*AggregateOptions) SetBatchSize Uses

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

SetBatchSize sets the value for the BatchSize field.

func (*AggregateOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*AggregateOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*AggregateOptions) SetComment Uses

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

SetComment sets the value for the Comment field.

func (*AggregateOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*AggregateOptions) SetMaxAwaitTime Uses

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

SetMaxAwaitTime sets the value for the MaxAwaitTime field.

func (*AggregateOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

type ArrayFilters Uses

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 Uses

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

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

func (*ArrayFilters) ToArrayDocument Uses

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 Uses

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 Uses

func AutoEncryption() *AutoEncryptionOptions

AutoEncryption creates a new AutoEncryptionOptions configured with default values.

func MergeAutoEncryptionOptions Uses

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

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

func (*AutoEncryptionOptions) SetBypassAutoEncryption Uses

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

SetBypassAutoEncryption specifies whether or not auto encryption should be done.

func (*AutoEncryptionOptions) SetExtraOptions Uses

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

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

func (*AutoEncryptionOptions) SetKeyVaultClientOptions Uses

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 Uses

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

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

func (*AutoEncryptionOptions) SetKmsProviders Uses

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

SetKmsProviders specifies options for KMS providers. This is required.

func (*AutoEncryptionOptions) SetSchemaMap Uses

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 Uses

type BucketOptions struct {
    // The name of the bucket. The default value is "fs".
    Name *string

    // The number of bytes in each chunk in the bucket. The default value is 255 KiB.
    ChunkSizeBytes *int32

    // The write concern for the bucket. The default value is the write concern of the database from which the bucket
    // is created.
    WriteConcern *writeconcern.WriteConcern

    // The read concern for the bucket. The default value is the read concern of the database from which the bucket
    // is created.
    ReadConcern *readconcern.ReadConcern

    // The read preference for the bucket. The default value is the read preference of the database from which the
    // bucket is created.
    ReadPreference *readpref.ReadPref
}

BucketOptions represents options that can be used to configure GridFS bucket.

func GridFSBucket Uses

func GridFSBucket() *BucketOptions

GridFSBucket creates a new BucketOptions instance.

func MergeBucketOptions Uses

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

MergeBucketOptions combines the given BucketOptions instances into a single BucketOptions in a last-one-wins fashion.

func (*BucketOptions) SetChunkSizeBytes Uses

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

SetChunkSizeBytes sets the value for the ChunkSize field.

func (*BucketOptions) SetName Uses

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

SetName sets the value for the Name field.

func (*BucketOptions) SetReadConcern Uses

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

SetReadConcern sets the value for the ReadConcern field.

func (*BucketOptions) SetReadPreference Uses

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

SetReadPreference sets the value for the ReadPreference field.

func (*BucketOptions) SetWriteConcern Uses

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

SetWriteConcern sets the value for the WriteConcern field.

type BulkWriteOptions Uses

type BulkWriteOptions struct {
    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // If true, no writes will be executed after one fails. The default value is true.
    Ordered *bool
}

BulkWriteOptions represents options that can be used to configure a BulkWrite operation.

func BulkWrite Uses

func BulkWrite() *BulkWriteOptions

BulkWrite creates a new *BulkWriteOptions instance.

func MergeBulkWriteOptions Uses

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

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

func (*BulkWriteOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*BulkWriteOptions) SetOrdered Uses

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

SetOrdered sets the value for the Ordered field.

type ChangeStreamOptions Uses

type ChangeStreamOptions struct {
    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // Specifies whether the updated document should be returned in change notifications for update operations along
    // with the deltas describing the changes made to the document. The default is options.Default, which means that
    // the updated document will not be included in the change notification.
    FullDocument *FullDocument

    // The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
    MaxAwaitTime *time.Duration

    // A document specifying the logical starting point for the change stream. Only changes corresponding to an oplog
    // entry immediately after the resume token will be returned. If this is specified, StartAtOperationTime and
    // StartAfter must not be set.
    ResumeAfter interface{}

    // If specified, the change stream will only return changes that occurred at or after the given timestamp. This
    // option is only valid for MongoDB versions >= 4.0. If this is specified, ResumeAfter and StartAfter must not be
    // set.
    StartAtOperationTime *primitive.Timestamp

    // A document specifying the logical starting point for the change stream. This is similar to the ResumeAfter
    // option, but allows a resume token from an "invalidate" notification to be used. This allows a change stream on a
    // collection to be resumed after the collection has been dropped and recreated or renamed. Only changes
    // corresponding to an oplog entry immediately after the specified token will be returned. If this is specified,
    // ResumeAfter and StartAtOperationTime must not be set. This option is only valid for MongoDB versions >= 4.1.1.
    StartAfter interface{}
}

ChangeStreamOptions represents options that can be used to configure a Watch operation.

func ChangeStream Uses

func ChangeStream() *ChangeStreamOptions

ChangeStream creates a new ChangeStreamOptions instance.

func MergeChangeStreamOptions Uses

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

MergeChangeStreamOptions combines the given ChangeStreamOptions instances into a single ChangeStreamOptions in a last-one-wins fashion.

func (*ChangeStreamOptions) SetBatchSize Uses

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

SetBatchSize sets the value for the BatchSize field.

func (*ChangeStreamOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*ChangeStreamOptions) SetFullDocument Uses

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

SetFullDocument sets the value for the FullDocument field.

func (*ChangeStreamOptions) SetMaxAwaitTime Uses

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

SetMaxAwaitTime sets the value for the MaxAwaitTime field.

func (*ChangeStreamOptions) SetResumeAfter Uses

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

SetResumeAfter sets the value for the ResumeAfter field.

func (*ChangeStreamOptions) SetStartAfter Uses

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

SetStartAfter sets the value for the StartAfter field.

func (*ChangeStreamOptions) SetStartAtOperationTime Uses

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

SetStartAtOperationTime sets the value for the StartAtOperationTime field.

type ClientEncryptionOptions Uses

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

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

func ClientEncryption Uses

func ClientEncryption() *ClientEncryptionOptions

ClientEncryption creates a new ClientEncryptionOptions instance.

func MergeClientEncryptionOptions Uses

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

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

func (*ClientEncryptionOptions) SetKeyVaultNamespace Uses

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

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

func (*ClientEncryptionOptions) SetKmsProviders Uses

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

SetKmsProviders specifies options for KMS providers. This is required.

type ClientOptions Uses

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

    // AuthenticateToAnything skips server type checks when deciding if authentication is possible.
    //
    // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
    // release.
    AuthenticateToAnything *bool

    // Deployment specifies a custom deployment to use for the new Client.
    //
    // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
    // release.
    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 Uses

func Client() *ClientOptions

Client creates a new ClientOptions instance.

func MergeClientOptions Uses

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 Uses

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) GetURI Uses

func (c *ClientOptions) GetURI() string

GetURI returns the original URI used to configure the ClientOptions instance. If ApplyURI was not called during construction, this returns "".

func (*ClientOptions) SetAppName Uses

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 Uses

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 Uses

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 Uses

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 server version >= 4.2, and driver version >= 1.2.0 with cgo support enabled or driver version >= 1.3.0

without cgo

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 configuring compression on the server and the server-side defaults.

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 Uses

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 Uses

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 with the Timeout field set to ConnectTimeout. See https://golang.org/pkg/net/#Dialer for more information about the net.Dialer type.

func (*ClientOptions) SetDirect Uses

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

SetDirect specifies whether or not a direct connect should be made. 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 "directConnection" URI option. This option cannot be set to true if multiple hosts are specified, either through ApplyURI or SetHosts, or an SRV URI is used.

As of driver version 1.4, the "connect" URI option has been deprecated and replaced with "directConnection". The "connect" URI option has two values:

1. "connect=direct" for direct connections. This corresponds to "directConnection=true".

2. "connect=automatic" for automatic discovery. This corresponds to "directConnection=false"

If the "connect" and "directConnection" URI options are both specified in the connection string, their values must not conflict. Direct connections are not valid if multiple hosts are specified or an SRV URI is used. The default value for this option is false.

func (*ClientOptions) SetDisableOCSPEndpointCheck Uses

func (c *ClientOptions) SetDisableOCSPEndpointCheck(disableCheck bool) *ClientOptions

SetDisableOCSPEndpointCheck specifies whether or not the driver should reach out to OCSP responders to verify the certificate status for certificates presented by the server that contain a list of OCSP responders.

If set to true, the driver will verify the status of the certificate using a response stapled by the server, if there is one, but will not send an HTTP request to any responders if there is no staple. In this case, the driver will continue the connection even though the certificate status is not known.

This can also be set through the tlsDisableOCSPEndpointCheck URI option. Both this URI option and tlsInsecure must not be set at the same time and will error if they are. The default value is false.

func (*ClientOptions) SetHeartbeatInterval Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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) SetServerMonitor Uses

func (c *ClientOptions) SetServerMonitor(m *event.ServerMonitor) *ClientOptions

SetServerMonitor specifies an SDAM monitor used to monitor SDAM events.

func (*ClientOptions) SetServerSelectionTimeout Uses

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 Uses

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 Uses

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. Either "tlsCertificateKeyFile" (or "sslClientCertificateKeyFile") or a combination of "tlsCertificateFile" and "tlsPrivateKeyFile". The "tlsCertificateKeyFile" option specifies a path to the client certificate and private key, which must be concatenated into one file. The "tlsCertificateFile" and "tlsPrivateKey" combination specifies separate paths to the client certificate and private key, respectively. Note that if "tlsCertificateKeyFile" is used, the other two options must not be specified.

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 Uses

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

SetWriteConcern specifies the write concern to use to for write operations. This can also be set 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 Uses

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 Uses

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 Uses

func (c *ClientOptions) Validate() error

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

type Collation Uses

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 Uses

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

ToDocument converts the Collation to a bson.Raw.

type CollectionOptions Uses

type CollectionOptions struct {
    // The read concern to use for operations executed on the Collection. The default value is nil, which means that
    // the read concern of the database used to configure the Collection will be used.
    ReadConcern *readconcern.ReadConcern

    // The write concern to use for operations executed on the Collection. The default value is nil, which means that
    // the write concern of the database used to configure the Collection will be used.
    WriteConcern *writeconcern.WriteConcern

    // The read preference to use for operations executed on the Collection. The default value is nil, which means that
    // the read preference of the database used to configure the Collection will be used.
    ReadPreference *readpref.ReadPref

    // The BSON registry to marshal and unmarshal documents for operations executed on the Collection. The default value
    // is nil, which means that the registry of the database used to configure the Collection will be used.
    Registry *bsoncodec.Registry
}

CollectionOptions represents options that can be used to configure a Collection.

func Collection Uses

func Collection() *CollectionOptions

Collection creates a new CollectionOptions instance.

func MergeCollectionOptions Uses

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

MergeCollectionOptions combines the given CollectionOptions instances into a single *CollectionOptions in a last-one-wins fashion.

func (*CollectionOptions) SetReadConcern Uses

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

SetReadConcern sets the value for the ReadConcern field.

func (*CollectionOptions) SetReadPreference Uses

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

SetReadPreference sets the value for the ReadPreference field.

func (*CollectionOptions) SetRegistry Uses

func (c *CollectionOptions) SetRegistry(r *bsoncodec.Registry) *CollectionOptions

SetRegistry sets the value for the Registry field.

func (*CollectionOptions) SetWriteConcern Uses

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

SetWriteConcern sets the value for the WriteConcern field.

type ContextDialer Uses

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 Uses

type CountOptions struct {
    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The index to use for the aggregation. This should either be the index name as a string or the index specification
    // as a document. The default value is nil, which means that no hint will be sent.
    Hint interface{}

    // The maximum number of documents to count. The default value is 0, which means that there is no limit and all
    // documents matching the filter will be counted.
    Limit *int64

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there is
    // no time limit for query execution.
    MaxTime *time.Duration

    // The number of documents to skip before counting. The default value is 0.
    Skip *int64
}

CountOptions represents options that can be used to configure a CountDocuments operation.

func Count Uses

func Count() *CountOptions

Count creates a new CountOptions instance.

func MergeCountOptions Uses

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

MergeCountOptions combines the given CountOptions instances into a single CountOptions in a last-one-wins fashion.

func (*CountOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*CountOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*CountOptions) SetLimit Uses

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

SetLimit sets the value for the Limit field.

func (*CountOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

func (*CountOptions) SetSkip Uses

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

SetSkip sets the value for the Skip field.

type CreateCollectionOptions Uses

type CreateCollectionOptions struct {
    // Specifies if the collection is capped (see https://docs.mongodb.com/manual/core/capped-collections/). If true,
    // the SizeInBytes option must also be specified. The default value is false.
    Capped *bool

    // Specifies the default collation for the new collection. This option is only valid for MongoDB versions >= 3.4.
    // For previous server versions, the driver will return an error if this option is used. The default value is nil.
    Collation *Collation

    // Specifies a default configuration for indexes on the collection. This option is only valid for MongoDB versions
    // >= 3.4. The default value is nil, meaning indexes will be configured using server defaults.
    DefaultIndexOptions *DefaultIndexOptions

    // Specifies the maximum number of documents allowed in a capped collection. The limit specified by the SizeInBytes
    // option takes precedence over this option. If a capped collection reaches its size limit, old documents will be
    // removed, regardless of the number of documents in the collection. The default value is 0, meaning the maximum
    // number of documents is unbounded.
    MaxDocuments *int64

    // Specifies the maximum size in bytes for a capped collection. The default value is 0.
    SizeInBytes *int64

    // Specifies the storage engine to use for the index. The value must be a document in the form
    // {<storage engine name>: <options>}. The default value is nil, which means that the default storage engine
    // will be used.
    StorageEngine interface{}

    // Specifies what should happen if a document being inserted does not pass validation. Valid values are "error" and
    // "warn". See https://docs.mongodb.com/manual/core/schema-validation/#accept-or-reject-invalid-documents for more
    // information. This option is only valid for MongoDB versions >= 3.2. The default value is "error".
    ValidationAction *string

    // Specifies how strictly the server applies validation rules to existing documents in the collection during update
    // operations. Valid values are "off", "strict", and "moderate". See
    // https://docs.mongodb.com/manual/core/schema-validation/#existing-documents for more information. This option is
    // only valid for MongoDB versions >= 3.2. The default value is "strict".
    ValidationLevel *string

    // A document specifying validation rules for the collection. See
    // https://docs.mongodb.com/manual/core/schema-validation/ for more information about schema validation. This option
    // is only valid for MongoDB versions >= 3.2. The default value is nil, meaning no validator will be used for the
    // collection.
    Validator interface{}
}

CreateCollectionOptions represents options that can be used to configure a CreateCollection operation.

func CreateCollection Uses

func CreateCollection() *CreateCollectionOptions

CreateCollection creates a new CreateCollectionOptions instance.

func MergeCreateCollectionOptions Uses

func MergeCreateCollectionOptions(opts ...*CreateCollectionOptions) *CreateCollectionOptions

MergeCreateCollectionOptions combines the given CreateCollectionOptions instances into a single CreateCollectionOptions in a last-one-wins fashion.

func (*CreateCollectionOptions) SetCapped Uses

func (c *CreateCollectionOptions) SetCapped(capped bool) *CreateCollectionOptions

SetCapped sets the value for the Capped field.

func (*CreateCollectionOptions) SetCollation Uses

func (c *CreateCollectionOptions) SetCollation(collation *Collation) *CreateCollectionOptions

SetCollation sets the value for the Collation field.

func (*CreateCollectionOptions) SetDefaultIndexOptions Uses

func (c *CreateCollectionOptions) SetDefaultIndexOptions(opts *DefaultIndexOptions) *CreateCollectionOptions

SetDefaultIndexOptions sets the value for the DefaultIndexOptions field.

func (*CreateCollectionOptions) SetMaxDocuments Uses

func (c *CreateCollectionOptions) SetMaxDocuments(max int64) *CreateCollectionOptions

SetMaxDocuments sets the value for the MaxDocuments field.

func (*CreateCollectionOptions) SetSizeInBytes Uses

func (c *CreateCollectionOptions) SetSizeInBytes(size int64) *CreateCollectionOptions

SetSizeInBytes sets the value for the SizeInBytes field.

func (*CreateCollectionOptions) SetStorageEngine Uses

func (c *CreateCollectionOptions) SetStorageEngine(storageEngine interface{}) *CreateCollectionOptions

SetStorageEngine sets the value for the StorageEngine field.

func (*CreateCollectionOptions) SetValidationAction Uses

func (c *CreateCollectionOptions) SetValidationAction(action string) *CreateCollectionOptions

SetValidationAction sets the value for the ValidationAction field.

func (*CreateCollectionOptions) SetValidationLevel Uses

func (c *CreateCollectionOptions) SetValidationLevel(level string) *CreateCollectionOptions

SetValidationLevel sets the value for the ValidationLevel field.

func (*CreateCollectionOptions) SetValidator Uses

func (c *CreateCollectionOptions) SetValidator(validator interface{}) *CreateCollectionOptions

SetValidator sets the value for the Validator field.

type CreateIndexesOptions Uses

type CreateIndexesOptions struct {
    // The number of data-bearing members of a replica set, including the primary, that must complete the index builds
    // successfully before the primary marks the indexes as ready. This should either be a string or int32 value. The
    // semantics of the values are as follows:
    //
    // 1. String: specifies a tag. All members with that tag must complete the build.
    // 2. int: the number of members that must complete the build.
    // 3. "majority": A special value to indicate that more than half the nodes must complete the build.
    // 4. "votingMembers": A special value to indicate that all voting data-bearing nodes must complete.
    //
    // This option is only available on MongoDB versions >= 4.4. A client-side error will be returned if the option
    // is specified for MongoDB versions <= 4.2. The default value is nil, meaning that the server-side default will be
    // used. See dochub.mongodb.org/core/index-commit-quorum for more information.
    CommitQuorum interface{}

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration
}

CreateIndexesOptions represents options that can be used to configure IndexView.CreateOne and IndexView.CreateMany operations.

func CreateIndexes Uses

func CreateIndexes() *CreateIndexesOptions

CreateIndexes creates a new CreateIndexesOptions instance.

func MergeCreateIndexesOptions Uses

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

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

func (*CreateIndexesOptions) SetCommitQuorumInt Uses

func (c *CreateIndexesOptions) SetCommitQuorumInt(quorum int32) *CreateIndexesOptions

SetCommitQuorumInt sets the value for the CommitQuorum field as an int32.

func (*CreateIndexesOptions) SetCommitQuorumMajority Uses

func (c *CreateIndexesOptions) SetCommitQuorumMajority() *CreateIndexesOptions

SetCommitQuorumMajority sets the value for the CommitQuorum to special "majority" value.

func (*CreateIndexesOptions) SetCommitQuorumString Uses

func (c *CreateIndexesOptions) SetCommitQuorumString(quorum string) *CreateIndexesOptions

SetCommitQuorumString sets the value for the CommitQuorum field as a string.

func (*CreateIndexesOptions) SetCommitQuorumVotingMembers Uses

func (c *CreateIndexesOptions) SetCommitQuorumVotingMembers() *CreateIndexesOptions

SetCommitQuorumVotingMembers sets the value for the CommitQuorum to special "votingMembers" value.

func (*CreateIndexesOptions) SetMaxTime Uses

func (c *CreateIndexesOptions) SetMaxTime(d time.Duration) *CreateIndexesOptions

SetMaxTime sets the value for the MaxTime field.

type CreateViewOptions Uses

type CreateViewOptions struct {
    // Specifies the default collation for the new collection. This option is only valid for MongoDB versions >= 3.4.
    // For previous server versions, the driver will return an error if this option is used. The default value is nil.
    Collation *Collation
}

CreateViewOptions represents options that can be used to configure a CreateView operation.

func CreateView Uses

func CreateView() *CreateViewOptions

CreateView creates an new CreateViewOptions instance.

func MergeCreateViewOptions Uses

func MergeCreateViewOptions(opts ...*CreateViewOptions) *CreateViewOptions

MergeCreateViewOptions combines the given CreateViewOptions instances into a single CreateViewOptions in a last-one-wins fashion.

func (*CreateViewOptions) SetCollation Uses

func (c *CreateViewOptions) SetCollation(collation *Collation) *CreateViewOptions

SetCollation sets the value for the Collation field.

type Credential Uses

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", "MONGODB-X509", and "MONGODB-AWS". 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.

4. AWS_SESSION_TOKEN: The AWS token for MONGODB-AWS authentication. This is optional and used for authentication with temporary credentials.

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: For GSSAPI, this must be true if a password is specified, even if the password is the empty string, and false if no password is specified, indicating that the password should be taken from the context of the running process. For other mechanisms, this field is ignored.

type CursorType Uses

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 Uses

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

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

func DataKey Uses

func DataKey() *DataKeyOptions

DataKey creates a new DataKeyOptions instance.

func MergeDataKeyOptions Uses

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

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

func (*DataKeyOptions) SetKeyAltNames Uses

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 Uses

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 Uses

type DatabaseOptions struct {
    // The read concern to use for operations executed on the Database. The default value is nil, which means that
    // the read concern of the client used to configure the Database will be used.
    ReadConcern *readconcern.ReadConcern

    // The write concern to use for operations executed on the Database. The default value is nil, which means that the
    // write concern of the client used to configure the Database will be used.
    WriteConcern *writeconcern.WriteConcern

    // The read preference to use for operations executed on the Database. The default value is nil, which means that
    // the read preference of the client used to configure the Database will be used.
    ReadPreference *readpref.ReadPref

    // The BSON registry to marshal and unmarshal documents for operations executed on the Database. The default value
    // is nil, which means that the registry of the client used to configure the Database will be used.
    Registry *bsoncodec.Registry
}

DatabaseOptions represents options that can be used to configure a Database.

func Database Uses

func Database() *DatabaseOptions

Database creates a new DatabaseOptions instance.

func MergeDatabaseOptions Uses

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

MergeDatabaseOptions combines the given DatabaseOptions instances into a single DatabaseOptions in a last-one-wins fashion.

func (*DatabaseOptions) SetReadConcern Uses

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

SetReadConcern sets the value for the ReadConcern field.

func (*DatabaseOptions) SetReadPreference Uses

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

SetReadPreference sets the value for the ReadPreference field.

func (*DatabaseOptions) SetRegistry Uses

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

SetRegistry sets the value for the Registry field.

func (*DatabaseOptions) SetWriteConcern Uses

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

SetWriteConcern sets the value for the WriteConcern field.

type DefaultIndexOptions Uses

type DefaultIndexOptions struct {
    // Specifies the storage engine to use for the index. The value must be a document in the form
    // {<storage engine name>: <options>}. The default value is nil, which means that the default storage engine
    // will be used.
    StorageEngine interface{}
}

DefaultIndexOptions represents the default options for a collection to apply on new indexes. This type can be used when creating a new collection through the CreateCollectionOptions.SetDefaultIndexOptions method.

func DefaultIndex Uses

func DefaultIndex() *DefaultIndexOptions

DefaultIndex creates a new DefaultIndexOptions instance.

func (*DefaultIndexOptions) SetStorageEngine Uses

func (d *DefaultIndexOptions) SetStorageEngine(storageEngine interface{}) *DefaultIndexOptions

SetStorageEngine sets the value for the StorageEngine field.

type DeleteOptions Uses

type DeleteOptions struct {
    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. This option is only valid for MongoDB versions >= 4.4. Server versions >= 3.4 will return an error
    // if this option is specified. For server versions < 3.4, the driver will return a client-side error if this option
    // is specified. The driver will return an error if this option is specified during an unacknowledged write
    // operation. The default value is nil, which means that no hint will be sent.
    Hint interface{}
}

DeleteOptions represents options that can be used to configure DeleteOne and DeleteMany operations.

func Delete Uses

func Delete() *DeleteOptions

Delete creates a new DeleteOptions instance.

func MergeDeleteOptions Uses

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

MergeDeleteOptions combines the given DeleteOptions instances into a single DeleteOptions in a last-one-wins fashion.

func (*DeleteOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*DeleteOptions) SetHint Uses

func (do *DeleteOptions) SetHint(hint interface{}) *DeleteOptions

SetHint sets the value for the Hint field.

type DistinctOptions Uses

type DistinctOptions struct {
    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration
}

DistinctOptions represents options that can be used to configure a Distinct operation.

func Distinct Uses

func Distinct() *DistinctOptions

Distinct creates a new DistinctOptions instance.

func MergeDistinctOptions Uses

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

MergeDistinctOptions combines the given DistinctOptions instances into a single DistinctOptions in a last-one-wins fashion.

func (*DistinctOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*DistinctOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

type DropIndexesOptions Uses

type DropIndexesOptions struct {
    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration
}

DropIndexesOptions represents options that can be used to configure IndexView.DropOne and IndexView.DropAll operations.

func DropIndexes Uses

func DropIndexes() *DropIndexesOptions

DropIndexes creates a new DropIndexesOptions instance.

func MergeDropIndexesOptions Uses

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

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

func (*DropIndexesOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

type EncryptOptions Uses

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

EncryptOptions represents options to explicitly encrypt a value.

func Encrypt Uses

func Encrypt() *EncryptOptions

Encrypt creates a new EncryptOptions instance.

func MergeEncryptOptions Uses

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

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

func (*EncryptOptions) SetAlgorithm Uses

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 Uses

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

SetKeyAltName identifies a key vault document by 'keyAltName'.

func (*EncryptOptions) SetKeyID Uses

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 Uses

type EstimatedDocumentCountOptions struct {
    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration
}

EstimatedDocumentCountOptions represents options that can be used to configure an EstimatedDocumentCount operation.

func EstimatedDocumentCount Uses

func EstimatedDocumentCount() *EstimatedDocumentCountOptions

EstimatedDocumentCount creates a new EstimatedDocumentCountOptions instance.

func MergeEstimatedDocumentCountOptions Uses

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

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

func (*EstimatedDocumentCountOptions) SetMaxTime Uses

func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions

SetMaxTime sets the value for the MaxTime field.

type FindOneAndDeleteOptions Uses

type FindOneAndDeleteOptions struct {
    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // A document describing which fields will be included in the document returned by the operation. The default value
    // is nil, which means all fields will be included.
    Projection interface{}

    // A document specifying which document should be replaced if the filter used by the operation matches multiple
    // documents in the collection. If set, the first document in the sorted order will be selected for replacement.
    // The default value is nil.
    Sort interface{}

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. This option is only valid for MongoDB versions >= 4.4. MongoDB version 4.2 will report an error if
    // this option is specified. For server versions < 4.2, the driver will return an error if this option is specified.
    // The driver will return an error if this option is used with during an unacknowledged write operation. The default
    // value is nil, which means that no hint will be sent.
    Hint interface{}
}

FindOneAndDeleteOptions represents options that can be used to configure a FindOneAndDelete operation.

func FindOneAndDelete Uses

func FindOneAndDelete() *FindOneAndDeleteOptions

FindOneAndDelete creates a new FindOneAndDeleteOptions instance.

func MergeFindOneAndDeleteOptions Uses

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

MergeFindOneAndDeleteOptions combines the given FindOneAndDeleteOptions instances into a single FindOneAndDeleteOptions in a last-one-wins fashion.

func (*FindOneAndDeleteOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*FindOneAndDeleteOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*FindOneAndDeleteOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

func (*FindOneAndDeleteOptions) SetProjection Uses

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

SetProjection sets the value for the Projection field.

func (*FindOneAndDeleteOptions) SetSort Uses

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

SetSort sets the value for the Sort field.

type FindOneAndReplaceOptions Uses

type FindOneAndReplaceOptions struct {
    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // A document describing which fields will be included in the document returned by the operation. The default value
    // is nil, which means all fields will be included.
    Projection interface{}

    // Specifies whether the original or replaced document should be returned by the operation. The default value is
    // Before, which means the original document will be returned from before the replacement is performed.
    ReturnDocument *ReturnDocument

    // A document specifying which document should be replaced if the filter used by the operation matches multiple
    // documents in the collection. If set, the first document in the sorted order will be replaced.
    // The default value is nil.
    Sort interface{}

    // If true, a new document will be inserted if the filter does not match any documents in the collection. The
    // default value is false.
    Upsert *bool

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. This option is only valid for MongoDB versions >= 4.4. MongoDB version 4.2 will report an error if
    // this option is specified. For server versions < 4.2, the driver will return an error if this option is specified.
    // The driver will return an error if this option is used with during an unacknowledged write operation. The default
    // value is nil, which means that no hint will be sent.
    Hint interface{}
}

FindOneAndReplaceOptions represents options that can be used to configure a FindOneAndReplace instance.

func FindOneAndReplace Uses

func FindOneAndReplace() *FindOneAndReplaceOptions

FindOneAndReplace creates a new FindOneAndReplaceOptions instance.

func MergeFindOneAndReplaceOptions Uses

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

MergeFindOneAndReplaceOptions combines the given FindOneAndReplaceOptions instances into a single FindOneAndReplaceOptions in a last-one-wins fashion.

func (*FindOneAndReplaceOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*FindOneAndReplaceOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*FindOneAndReplaceOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*FindOneAndReplaceOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

func (*FindOneAndReplaceOptions) SetProjection Uses

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

SetProjection sets the value for the Projection field.

func (*FindOneAndReplaceOptions) SetReturnDocument Uses

func (f *FindOneAndReplaceOptions) SetReturnDocument(rd ReturnDocument) *FindOneAndReplaceOptions

SetReturnDocument sets the value for the ReturnDocument field.

func (*FindOneAndReplaceOptions) SetSort Uses

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

SetSort sets the value for the Sort field.

func (*FindOneAndReplaceOptions) SetUpsert Uses

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

SetUpsert sets the value for the Upsert field.

type FindOneAndUpdateOptions Uses

type FindOneAndUpdateOptions struct {
    // A set of filters specifying to which array elements an update should apply. This option is only valid for MongoDB
    // versions >= 3.6. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the update will apply to all array elements.
    ArrayFilters *ArrayFilters

    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // A document describing which fields will be included in the document returned by the operation. The default value
    // is nil, which means all fields will be included.
    Projection interface{}

    // Specifies whether the original or replaced document should be returned by the operation. The default value is
    // Before, which means the original document will be returned before the replacement is performed.
    ReturnDocument *ReturnDocument

    // A document specifying which document should be updated if the filter used by the operation matches multiple
    // documents in the collection. If set, the first document in the sorted order will be updated.
    // The default value is nil.
    Sort interface{}

    // If true, a new document will be inserted if the filter does not match any documents in the collection. The
    // default value is false.
    Upsert *bool

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. This option is only valid for MongoDB versions >= 4.4. MongoDB version 4.2 will report an error if
    // this option is specified. For server versions < 4.2, the driver will return an error if this option is specified.
    // The driver will return an error if this option is used with during an unacknowledged write operation. The default
    // value is nil, which means that no hint will be sent.
    Hint interface{}
}

FindOneAndUpdateOptions represents options that can be used to configure a FindOneAndUpdate options.

func FindOneAndUpdate Uses

func FindOneAndUpdate() *FindOneAndUpdateOptions

FindOneAndUpdate creates a new FindOneAndUpdateOptions instance.

func MergeFindOneAndUpdateOptions Uses

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

MergeFindOneAndUpdateOptions combines the given FindOneAndUpdateOptions instances into a single FindOneAndUpdateOptions in a last-one-wins fashion.

func (*FindOneAndUpdateOptions) SetArrayFilters Uses

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

SetArrayFilters sets the value for the ArrayFilters field.

func (*FindOneAndUpdateOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*FindOneAndUpdateOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*FindOneAndUpdateOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*FindOneAndUpdateOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

func (*FindOneAndUpdateOptions) SetProjection Uses

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

SetProjection sets the value for the Projection field.

func (*FindOneAndUpdateOptions) SetReturnDocument Uses

func (f *FindOneAndUpdateOptions) SetReturnDocument(rd ReturnDocument) *FindOneAndUpdateOptions

SetReturnDocument sets the value for the ReturnDocument field.

func (*FindOneAndUpdateOptions) SetSort Uses

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

SetSort sets the value for the Sort field.

func (*FindOneAndUpdateOptions) SetUpsert Uses

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

SetUpsert sets the value for the Upsert field.

type FindOneOptions Uses

type FindOneOptions struct {
    // If true, an operation on a sharded cluster can return partial results if some shards are down rather than
    // returning an error. The default value is false.
    AllowPartialResults *bool

    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // A string that will be included in server logs, profiling logs, and currentOp queries to help trace the operation.
    // The default is the empty string, which means that no comment will be included in the logs.
    Comment *string

    // Specifies the type of cursor that should be created for the operation. The default is NonTailable, which means
    // that the cursor will be closed by the server when the last batch of documents is retrieved.
    CursorType *CursorType

    // The index to use for the aggregation. This should either be the index name as a string or the index specification
    // as a document. The default value is nil, which means that no hint will be sent.
    Hint interface{}

    // A document specifying the exclusive upper bound for a specific index. The default value is nil, which means that
    // there is no maximum value.
    Max interface{}

    // The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
    // This option is only valid for tailable await cursors (see the CursorType option for more information) and
    // MongoDB versions >= 3.2. For other cursor types or previous server versions, this option is ignored.
    MaxAwaitTime *time.Duration

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // A document specifying the inclusive lower bound for a specific index. The default value is 0, which means that
    // there is no minimum value.
    Min interface{}

    // If true, the cursor created by the operation will not timeout after a period of inactivity. The default value
    // is false.
    NoCursorTimeout *bool

    // This option is for internal replication use only and should not be set.
    OplogReplay *bool

    // A document describing which fields will be included in the document returned by the operation. The default value
    // is nil, which means all fields will be included.
    Projection interface{}

    // If true, the document returned by the operation will only contain fields corresponding to the index used. The
    // default value is false.
    ReturnKey *bool

    // If true, a $recordId field with a record identifier will be included in the document returned by the operation.
    // The default value is false.
    ShowRecordID *bool

    // The number of documents to skip before selecting the document to be returned. The default value is 0.
    Skip *int64

    // If true, the cursor will not return a document more than once because of an intervening write operation. The
    // default value is false.
    //
    // Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.
    Snapshot *bool

    // A document specifying the sort order to apply to the query. The first document in the sorted order will be
    // returned.
    Sort interface{}
}

FindOneOptions represents options that can be used to configure a FindOne operation.

func FindOne Uses

func FindOne() *FindOneOptions

FindOne creates a new FindOneOptions instance.

func MergeFindOneOptions Uses

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

MergeFindOneOptions combines the given FindOneOptions instances into a single FindOneOptions in a last-one-wins fashion.

func (*FindOneOptions) SetAllowPartialResults Uses

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

SetAllowPartialResults sets the value for the AllowPartialResults field.

func (*FindOneOptions) SetBatchSize Uses

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

SetBatchSize sets the value for the BatchSize field.

func (*FindOneOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*FindOneOptions) SetComment Uses

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

SetComment sets the value for the Comment field.

func (*FindOneOptions) SetCursorType Uses

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

SetCursorType sets the value for the CursorType field.

func (*FindOneOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*FindOneOptions) SetMax Uses

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

SetMax sets the value for the Max field.

func (*FindOneOptions) SetMaxAwaitTime Uses

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

SetMaxAwaitTime sets the value for the MaxAwaitTime field.

func (*FindOneOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

func (*FindOneOptions) SetMin Uses

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

SetMin sets the value for the Min field.

func (*FindOneOptions) SetNoCursorTimeout Uses

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

SetNoCursorTimeout sets the value for the NoCursorTimeout field.

func (*FindOneOptions) SetOplogReplay Uses

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

SetOplogReplay sets the value for the OplogReplay field.

func (*FindOneOptions) SetProjection Uses

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

SetProjection sets the value for the Projection field.

func (*FindOneOptions) SetReturnKey Uses

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

SetReturnKey sets the value for the ReturnKey field.

func (*FindOneOptions) SetShowRecordID Uses

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

SetShowRecordID sets the value for the ShowRecordID field.

func (*FindOneOptions) SetSkip Uses

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

SetSkip sets the value for the Skip field.

func (*FindOneOptions) SetSnapshot Uses

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

SetSnapshot sets the value for the Snapshot field.

Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.

func (*FindOneOptions) SetSort Uses

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

SetSort sets the value for the Sort field.

type FindOptions Uses

type FindOptions struct {
    // If true, the server can write temporary data to disk while executing the find operation. This option is only
    // valid for MongoDB versions >= 4.4. Server versions >= 3.2 will report an error if this option is specified. For
    // server versions < 3.2, the driver will return a client-side error if this option is specified. The default value
    // is false.
    AllowDiskUse *bool

    // If true, an operation on a sharded cluster can return partial results if some shards are down rather than
    // returning an error. The default value is false.
    AllowPartialResults *bool

    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // A string that will be included in server logs, profiling logs, and currentOp queries to help trace the operation.
    // The default is the empty string, which means that no comment will be included in the logs.
    Comment *string

    // Specifies the type of cursor that should be created for the operation. The default is NonTailable, which means
    // that the cursor will be closed by the server when the last batch of documents is retrieved.
    CursorType *CursorType

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. The default value is nil, which means that no hint will be sent.
    Hint interface{}

    // The maximum number of documents to return. The default value is 0, which means that all documents matching the
    // filter will be returned. A negative limit specifies that the resulting documents should be returned in a single
    // batch. The default value is 0.
    Limit *int64

    // A document specifying the exclusive upper bound for a specific index. The default value is nil, which means that
    // there is no maximum value.
    Max interface{}

    // The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
    // This option is only valid for tailable await cursors (see the CursorType option for more information) and
    // MongoDB versions >= 3.2. For other cursor types or previous server versions, this option is ignored.
    MaxAwaitTime *time.Duration

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // A document specifying the inclusive lower bound for a specific index. The default value is 0, which means that
    // there is no minimum value.
    Min interface{}

    // If true, the cursor created by the operation will not timeout after a period of inactivity. The default value
    // is false.
    NoCursorTimeout *bool

    // This option is for internal replication use only and should not be set.
    //
    // Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is
    // set.
    OplogReplay *bool

    // A document describing which fields will be included in the documents returned by the operation. The default value
    // is nil, which means all fields will be included.
    Projection interface{}

    // If true, the documents returned by the operation will only contain fields corresponding to the index used. The
    // default value is false.
    ReturnKey *bool

    // If true, a $recordId field with a record identifier will be included in the documents returned by the operation.
    // The default value is false.
    ShowRecordID *bool

    // The number of documents to skip before adding documents to the result. The default value is 0.
    Skip *int64

    // If true, the cursor will not return a document more than once because of an intervening write operation. The
    // default value is false.
    //
    // Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.
    Snapshot *bool

    // A document specifying the order in which documents should be returned.
    Sort interface{}
}

FindOptions represents options that can be used to configure a Find operation.

func Find Uses

func Find() *FindOptions

Find creates a new FindOptions instance.

func MergeFindOptions Uses

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

MergeFindOptions combines the given FindOptions instances into a single FindOptions in a last-one-wins fashion.

func (*FindOptions) SetAllowDiskUse Uses

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

SetAllowDiskUse sets the value for the AllowDiskUse field.

func (*FindOptions) SetAllowPartialResults Uses

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

SetAllowPartialResults sets the value for the AllowPartialResults field.

func (*FindOptions) SetBatchSize Uses

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

SetBatchSize sets the value for the BatchSize field.

func (*FindOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*FindOptions) SetComment Uses

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

SetComment sets the value for the Comment field.

func (*FindOptions) SetCursorType Uses

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

SetCursorType sets the value for the CursorType field.

func (*FindOptions) SetHint Uses

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

SetHint sets the value for the Hint field.

func (*FindOptions) SetLimit Uses

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

SetLimit sets the value for the Limit field.

func (*FindOptions) SetMax Uses

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

SetMax sets the value for the Max field.

func (*FindOptions) SetMaxAwaitTime Uses

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

SetMaxAwaitTime sets the value for the MaxAwaitTime field.

func (*FindOptions) SetMaxTime Uses

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

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

func (*FindOptions) SetMin Uses

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

SetMin sets the value for the Min field.

func (*FindOptions) SetNoCursorTimeout Uses

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

SetNoCursorTimeout sets the value for the NoCursorTimeout field.

func (*FindOptions) SetOplogReplay Uses

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

SetOplogReplay sets the value for the OplogReplay field.

Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is set.

func (*FindOptions) SetProjection Uses

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

SetProjection sets the value for the Projection field.

func (*FindOptions) SetReturnKey Uses

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

SetReturnKey sets the value for the ReturnKey field.

func (*FindOptions) SetShowRecordID Uses

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

SetShowRecordID sets the value for the ShowRecordID field.

func (*FindOptions) SetSkip Uses

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

SetSkip sets the value for the Skip field.

func (*FindOptions) SetSnapshot Uses

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

SetSnapshot sets the value for the Snapshot field.

Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.

func (*FindOptions) SetSort Uses

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

SetSort sets the value for the Sort field.

type FullDocument Uses

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 Uses

type GridFSFindOptions struct {
    // If true, the server can write temporary data to disk while executing the find operation. The default value
    // is false. This option is only valid for MongoDB versions >= 4.4. For previous server versions, the server will
    // return an error if this option is used.
    AllowDiskUse *bool

    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32

    // The maximum number of documents to return. The default value is 0, which means that all documents matching the
    // filter will be returned. A negative limit specifies that the resulting documents should be returned in a single
    // batch. The default value is 0.
    Limit *int32

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration

    // If true, the cursor created by the operation will not timeout after a period of inactivity. The default value
    // is false.
    NoCursorTimeout *bool

    // The number of documents to skip before adding documents to the result. The default value is 0.
    Skip *int32

    // A document specifying the order in which documents should be returned.
    Sort interface{}
}

GridFSFindOptions represents options that can be used to configure a GridFS Find operation.

func GridFSFind Uses

func GridFSFind() *GridFSFindOptions

GridFSFind creates a new GridFSFindOptions instance.

func MergeGridFSFindOptions Uses

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

MergeGridFSFindOptions combines the given GridFSFindOptions instances into a single GridFSFindOptions in a last-one-wins fashion.

func (*GridFSFindOptions) SetAllowDiskUse Uses

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

SetAllowDiskUse sets the value for the AllowDiskUse field.

func (*GridFSFindOptions) SetBatchSize Uses

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

SetBatchSize sets the value for the BatchSize field.

func (*GridFSFindOptions) SetLimit Uses

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

SetLimit sets the value for the Limit field.

func (*GridFSFindOptions) SetMaxTime Uses

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

SetMaxTime sets the value for the MaxTime field.

func (*GridFSFindOptions) SetNoCursorTimeout Uses

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

SetNoCursorTimeout sets the value for the NoCursorTimeout field.

func (*GridFSFindOptions) SetSkip Uses

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

SetSkip sets the value for the Skip field.

func (*GridFSFindOptions) SetSort Uses

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

SetSort sets the value for the Sort field.

type IndexOptions Uses

type IndexOptions struct {
    // If true, the index will be built in the background on the server and will not block other tasks. The default
    // value is false.
    //
    // Deprecated: This option has been deprecated in MongoDB version 4.2.
    Background *bool

    // The length of time, in seconds, for documents to remain in the collection. The default value is 0, which means
    // that documents will remain in the collection until they're explicitly deleted or the collection is dropped.
    ExpireAfterSeconds *int32

    // The name of the index. The default value is "[field1]_[direction1]_[field2]_[direction2]...". For example, an
    // index with the specification {name: 1, age: -1} will be named "name_1_age_-1".
    Name *string

    // If true, the index will only reference documents that contain the fields specified in the index. The default is
    // false.
    Sparse *bool

    // Specifies the storage engine to use for the index. The value must be a document in the form
    // {<storage engine name>: <options>}. The default value is nil, which means that the default storage engine
    // will be used. This option is only applicable for MongoDB versions >= 3.0 and is ignored for previous server
    // versions.
    StorageEngine interface{}

    // If true, the collection will not accept insertion or update of documents where the index key value matches an
    // existing value in the index. The default is false.
    Unique *bool

    // The index version number, either 0 or 1.
    Version *int32

    // The language that determines the list of stop words and the rules for the stemmer and tokenizer. This option
    // is only applicable for text indexes and is ignored for other index types. The default value is "english".
    DefaultLanguage *string

    // The name of the field in the collection's documents that contains the override language for the document. This
    // option is only applicable for text indexes and is ignored for other index types. The default value is the value
    // of the DefaultLanguage option.
    LanguageOverride *string

    // The index version number for a text index. See https://docs.mongodb.com/manual/core/index-text/#text-versions for
    // information about different version numbers.
    TextVersion *int32

    // A document that contains field and weight pairs. The weight is an integer ranging from 1 to 99,999, inclusive,
    // indicating the significance of the field relative to the other indexed fields in terms of the score. This option
    // is only applicable for text indexes and is ignored for other index types. The default value is nil, which means
    // that every field will have a weight of 1.
    Weights interface{}

    // The index version number for a 2D sphere index. See https://docs.mongodb.com/manual/core/2dsphere/#dsphere-v2 for
    // information about different version numbers.
    SphereVersion *int32

    // The precision of the stored geohash value of the location data. This option only applies to 2D indexes and is
    // ignored for other index types. The value must be between 1 and 32, inclusive. The default value is 26.
    Bits *int32

    // The upper inclusive boundary for longitude and latitude values. This option is only applicable to 2D indexes and
    // is ignored for other index types. The default value is 180.0.
    Max *float64

    // The lower inclusive boundary for longitude and latitude values. This option is only applicable to 2D indexes and
    // is ignored for other index types. The default value is -180.0.
    Min *float64

    // The number of units within which to group location values. Location values that are within BucketSize units of
    // each other will be grouped in the same bucket. This option is only applicable to geoHaystack indexes and is
    // ignored for other index types. The value must be greater than 0.
    BucketSize *int32

    // A document that defines which collection documents the index should reference. This option is only valid for
    // MongoDB versions >= 3.2 and is ignored for previous server versions.
    PartialFilterExpression interface{}

    // The collation to use for string comparisons for the index. This option is only valid for MongoDB versions >= 3.4.
    // For previous server versions, the driver will return an error if this option is used.
    Collation *Collation

    // A document that defines the wildcard projection for the index.
    WildcardProjection interface{}

    // If true, the index will exist on the target collection but will not be used by the query planner when executing
    // operations. This option is only valid for MongoDB versions >= 4.4. The default value is false.
    Hidden *bool
}

IndexOptions represents options that can be used to configure a new index created through the IndexView.CreateOne or IndexView.CreateMany operations.

func Index Uses

func Index() *IndexOptions

Index creates a new IndexOptions instance.

func MergeIndexOptions Uses

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

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

func (*IndexOptions) SetBackground Uses

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

SetBackground sets value for the Background field.

Deprecated: This option has been deprecated in MongoDB version 4.2.

func (*IndexOptions) SetBits Uses

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

SetBits sets the value for the Bits field.

func (*IndexOptions) SetBucketSize Uses

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

SetBucketSize sets the value for the BucketSize field

func (*IndexOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*IndexOptions) SetDefaultLanguage Uses

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

SetDefaultLanguage sets the value for the DefaultLanguage field.

func (*IndexOptions) SetExpireAfterSeconds Uses

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

SetExpireAfterSeconds sets value for the ExpireAfterSeconds field.

func (*IndexOptions) SetHidden Uses

func (i *IndexOptions) SetHidden(hidden bool) *IndexOptions

SetHidden sets the value for the Hidden field.

func (*IndexOptions) SetLanguageOverride Uses

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

SetLanguageOverride sets the value of the LanguageOverride field.

func (*IndexOptions) SetMax Uses

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

SetMax sets the value for the Max field.

func (*IndexOptions) SetMin Uses

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

SetMin sets the value for the Min field.

func (*IndexOptions) SetName Uses

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

SetName sets the value for the Name field.

func (*IndexOptions) SetPartialFilterExpression Uses

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

SetPartialFilterExpression sets the value for the PartialFilterExpression field.

func (*IndexOptions) SetSparse Uses

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

SetSparse sets the value of the Sparse field.

func (*IndexOptions) SetSphereVersion Uses

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

SetSphereVersion sets the value for the SphereVersion field.

func (*IndexOptions) SetStorageEngine Uses

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

SetStorageEngine sets the value for the StorageEngine field.

func (*IndexOptions) SetTextVersion Uses

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

SetTextVersion sets the value for the TextVersion field.

func (*IndexOptions) SetUnique Uses

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

SetUnique sets the value for the Unique field.

func (*IndexOptions) SetVersion Uses

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

SetVersion sets the value for the Version field.

func (*IndexOptions) SetWeights Uses

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

SetWeights sets the value for the Weights field.

func (*IndexOptions) SetWildcardProjection Uses

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

SetWildcardProjection sets the value for the WildcardProjection field.

type InsertManyOptions Uses

type InsertManyOptions struct {
    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // If true, no writes will be executed after one fails. The default value is true.
    Ordered *bool
}

InsertManyOptions represents options that can be used to configure an InsertMany operation.

func InsertMany Uses

func InsertMany() *InsertManyOptions

InsertMany creates a new InsertManyOptions instance.

func MergeInsertManyOptions Uses

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

MergeInsertManyOptions combines the givent InsertManyOptions instances into a single InsertManyOptions in a last one wins fashion.

func (*InsertManyOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*InsertManyOptions) SetOrdered Uses

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

SetOrdered sets the value for the Ordered field.

type InsertOneOptions Uses

type InsertOneOptions struct {
    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool
}

InsertOneOptions represents options that can be used to configure an InsertOne operation.

func InsertOne Uses

func InsertOne() *InsertOneOptions

InsertOne creates a new InsertOneOptions instance.

func MergeInsertOneOptions Uses

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

MergeInsertOneOptions combines the given InsertOneOptions instances into a single InsertOneOptions in a last-one-wins fashion.

func (*InsertOneOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

type ListCollectionsOptions Uses

type ListCollectionsOptions struct {
    // If true, each collection document will only contain a field for the collection name. The default value is false.
    NameOnly *bool

    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32
}

ListCollectionsOptions represents options that can be used to configure a ListCollections operation.

func ListCollections Uses

func ListCollections() *ListCollectionsOptions

ListCollections creates a new ListCollectionsOptions instance.

func MergeListCollectionsOptions Uses

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

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

func (*ListCollectionsOptions) SetBatchSize Uses

func (lc *ListCollectionsOptions) SetBatchSize(size int32) *ListCollectionsOptions

SetBatchSize sets the value for the BatchSize field.

func (*ListCollectionsOptions) SetNameOnly Uses

func (lc *ListCollectionsOptions) SetNameOnly(b bool) *ListCollectionsOptions

SetNameOnly sets the value for the NameOnly field.

type ListDatabasesOptions Uses

type ListDatabasesOptions struct {
    // If true, only the Name field of the returned DatabaseSpecification objects will be populated. The default value
    // is false.
    NameOnly *bool

    // If true, only the databases which the user is authorized to see will be returned. For more information about
    // the behavior of this option, see https://docs.mongodb.com/manual/reference/privilege-actions/#find. The default
    // value is true.
    AuthorizedDatabases *bool
}

ListDatabasesOptions represents options that can be used to configure a ListDatabases operation.

func ListDatabases Uses

func ListDatabases() *ListDatabasesOptions

ListDatabases creates a new ListDatabasesOptions instance.

func MergeListDatabasesOptions Uses

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

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

func (*ListDatabasesOptions) SetAuthorizedDatabases Uses

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

SetAuthorizedDatabases sets the value for the AuthorizedDatabases field.

func (*ListDatabasesOptions) SetNameOnly Uses

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

SetNameOnly sets the value for the NameOnly field.

type ListIndexesOptions Uses

type ListIndexesOptions struct {
    // The maximum number of documents to be included in each batch returned by the server.
    BatchSize *int32

    // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    // is no time limit for query execution.
    MaxTime *time.Duration
}

ListIndexesOptions represents options that can be used to configure an IndexView.List operation.

func ListIndexes Uses

func ListIndexes() *ListIndexesOptions

ListIndexes creates a new ListIndexesOptions instance.

func MergeListIndexesOptions Uses

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

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

func (*ListIndexesOptions) SetBatchSize Uses

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

SetBatchSize sets the value for the BatchSize field.

func (*ListIndexesOptions) SetMaxTime Uses

func (l *ListIndexesOptions) SetMaxTime(d time.Duration) *ListIndexesOptions

SetMaxTime sets the value for the MaxTime field.

type MarshalError Uses

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 Uses

func (me MarshalError) Error() string

Error implements the error interface.

type NameOptions Uses

type NameOptions struct {
    // Specifies the revision of the file to retrieve. 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.
    //
    // The default value is -1
    Revision *int32
}

NameOptions represents options that can be used to configure a GridFS DownloadByName operation.

func GridFSName Uses

func GridFSName() *NameOptions

GridFSName creates a new NameOptions instance.

func MergeNameOptions Uses

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

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

func (*NameOptions) SetRevision Uses

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

SetRevision sets the value for the Revision field.

type ReplaceOptions Uses

type ReplaceOptions struct {
    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. This option is only valid for MongoDB versions >= 4.2. Server versions >= 3.4 will return an error
    // if this option is specified. For server versions < 3.4, the driver will return a client-side error if this option
    // is specified. The driver will return an error if this option is specified during an unacknowledged write
    // operation. The default value is nil, which means that no hint will be sent.
    Hint interface{}

    // If true, a new document will be inserted if the filter does not match any documents in the collection. The
    // default value is false.
    Upsert *bool
}

ReplaceOptions represents options that can be used to configure a ReplaceOne operation.

func MergeReplaceOptions Uses

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

MergeReplaceOptions combines the given ReplaceOptions instances into a single ReplaceOptions in a last-one-wins fashion.

func Replace Uses

func Replace() *ReplaceOptions

Replace creates a new ReplaceOptions instance.

func (*ReplaceOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*ReplaceOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*ReplaceOptions) SetHint Uses

func (ro *ReplaceOptions) SetHint(h interface{}) *ReplaceOptions

SetHint sets the value for the Hint field.

func (*ReplaceOptions) SetUpsert Uses

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

SetUpsert sets the value for the Upsert field.

type ReturnDocument Uses

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 Uses

type RunCmdOptions struct {
    // The read preference to use for the operation. The default value is nil, which means that the primary read
    // preference will be used.
    ReadPreference *readpref.ReadPref
}

RunCmdOptions represents options that can be used to configure a RunCommand operation.

func MergeRunCmdOptions Uses

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

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

func RunCmd Uses

func RunCmd() *RunCmdOptions

RunCmd creates a new RunCmdOptions instance.

func (*RunCmdOptions) SetReadPreference Uses

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

SetReadPreference sets value for the ReadPreference field.

type SessionOptions Uses

type SessionOptions struct {
    // If true, causal consistency will be enabled for the session. The default value is true. See
    // https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#sessions for more information.
    CausalConsistency *bool

    // The default read concern for transactions started in the session. The default value is nil, which means that
    // the read concern of the client used to start the session will be used.
    DefaultReadConcern *readconcern.ReadConcern

    // The default read preference for transactions started in the session. The default value is nil, which means that
    // the read preference of the client used to start the session will be used.
    DefaultReadPreference *readpref.ReadPref

    // The default write concern for transactions started in the session. The default value is nil, which means that
    // the write concern of the client used to start the session will be used.
    DefaultWriteConcern *writeconcern.WriteConcern

    // The default maximum amount of time that a CommitTransaction operation executed in the session can run on the
    // server. The default value is nil, which means that that there is no time limit for execution.
    DefaultMaxCommitTime *time.Duration
}

SessionOptions represents options that can be used to configure a Session.

func MergeSessionOptions Uses

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

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

func Session Uses

func Session() *SessionOptions

Session creates a new SessionOptions instance.

func (*SessionOptions) SetCausalConsistency Uses

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

SetCausalConsistency sets the value for the CausalConsistency field.

func (*SessionOptions) SetDefaultMaxCommitTime Uses

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

SetDefaultMaxCommitTime sets the value for the DefaultMaxCommitTime field.

func (*SessionOptions) SetDefaultReadConcern Uses

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

SetDefaultReadConcern sets the value for the DefaultReadConcern field.

func (*SessionOptions) SetDefaultReadPreference Uses

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

SetDefaultReadPreference sets the value for the DefaultReadPreference field.

func (*SessionOptions) SetDefaultWriteConcern Uses

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

SetDefaultWriteConcern sets the value for the DefaultWriteConcern field.

type TransactionOptions Uses

type TransactionOptions struct {
    // The read concern for operations in the transaction. The default value is nil, which means that the default
    // read concern of the session used to start the transaction will be used.
    ReadConcern *readconcern.ReadConcern

    // The read preference for operations in the transaction. The default value is nil, which means that the default
    // read preference of the session used to start the transaction will be used.
    ReadPreference *readpref.ReadPref

    // The write concern for operations in the transaction. The default value is nil, which means that the default
    // write concern of the session used to start the transaction will be used.
    WriteConcern *writeconcern.WriteConcern

    // The maximum amount of time that a CommitTransaction operation can executed in the transaction can run on the
    // server. The default value is nil, which means that the default maximum commit time of the session used to
    // start the transaction will be used.
    MaxCommitTime *time.Duration
}

TransactionOptions represents options that can be used to configure a transaction.

func MergeTransactionOptions Uses

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

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

func Transaction Uses

func Transaction() *TransactionOptions

Transaction creates a new TransactionOptions instance.

func (*TransactionOptions) SetMaxCommitTime Uses

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

SetMaxCommitTime sets the value for the MaxCommitTime field.

func (*TransactionOptions) SetReadConcern Uses

func (t *TransactionOptions) SetReadConcern(rc *readconcern.ReadConcern) *TransactionOptions

SetReadConcern sets the value for the ReadConcern field.

func (*TransactionOptions) SetReadPreference Uses

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

SetReadPreference sets the value for the ReadPreference field.

func (*TransactionOptions) SetWriteConcern Uses

func (t *TransactionOptions) SetWriteConcern(wc *writeconcern.WriteConcern) *TransactionOptions

SetWriteConcern sets the value for the WriteConcern field.

type UpdateOptions Uses

type UpdateOptions struct {
    // A set of filters specifying to which array elements an update should apply. This option is only valid for MongoDB
    // versions >= 3.6. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the update will apply to all array elements.
    ArrayFilters *ArrayFilters

    // If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    // option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    // false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
    // validation.
    BypassDocumentValidation *bool

    // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    // default value is nil, which means the default collation of the collection will be used.
    Collation *Collation

    // The index to use for the operation. This should either be the index name as a string or the index specification
    // as a document. This option is only valid for MongoDB versions >= 4.2. Server versions >= 3.4 will return an error
    // if this option is specified. For server versions < 3.4, the driver will return a client-side error if this option
    // is specified. The driver will return an error if this option is specified during an unacknowledged write
    // operation. The default value is nil, which means that no hint will be sent.
    Hint interface{}

    // If true, a new document will be inserted if the filter does not match any documents in the collection. The
    // default value is false.
    Upsert *bool
}

UpdateOptions represents options that can be used to configure UpdateOne and UpdateMany operations.

func MergeUpdateOptions Uses

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

MergeUpdateOptions combines the given UpdateOptions instances into a single UpdateOptions in a last-one-wins fashion.

func Update Uses

func Update() *UpdateOptions

Update creates a new UpdateOptions instance.

func (*UpdateOptions) SetArrayFilters Uses

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

SetArrayFilters sets the value for the ArrayFilters field.

func (*UpdateOptions) SetBypassDocumentValidation Uses

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

SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.

func (*UpdateOptions) SetCollation Uses

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

SetCollation sets the value for the Collation field.

func (*UpdateOptions) SetHint Uses

func (uo *UpdateOptions) SetHint(h interface{}) *UpdateOptions

SetHint sets the value for the Hint field.

func (*UpdateOptions) SetUpsert Uses

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

SetUpsert sets the value for the Upsert field.

type UploadOptions Uses

type UploadOptions struct {
    // The number of bytes in each chunk in the bucket. The default value is DefaultChunkSize (255 KiB).
    ChunkSizeBytes *int32

    // Additional application data that will be stored in the "metadata" field of the document in the files collection.
    // The default value is nil, which means that the document in the files collection will not contain a "metadata"
    // field.
    Metadata interface{}

    // The BSON registry to use for converting filters to BSON documents. The default value is bson.DefaultRegistry.
    Registry *bsoncodec.Registry
}

UploadOptions represents options that can be used to configure a GridFS upload operation.

func GridFSUpload Uses

func GridFSUpload() *UploadOptions

GridFSUpload creates a new UploadOptions instance.

func MergeUploadOptions Uses

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

MergeUploadOptions combines the given UploadOptions instances into a single UploadOptions in a last-one-wins fashion.

func (*UploadOptions) SetChunkSizeBytes Uses

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

SetChunkSizeBytes sets the value for the ChunkSize field.

func (*UploadOptions) SetMetadata Uses

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

SetMetadata sets the value for the Metadata field.

Package options imports 25 packages (graph) and is imported by 528 packages. Updated 2020-09-22. Refresh now. Tools for package owners.