mongodb

package module
v0.0.0-...-989e8db Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package mongodb implements a storage provider conforming to the storage interface in aries-framework-go. It is compatible with MongoDB v4.0.0, v4.2.8, and v5.0.0. It is also compatible with Amazon DocumentDB 4.0.0. It may be compatible with other versions, but they haven't been tested.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(opts *Provider)

Option represents an option for a MongoDB Provider.

func WithDBPrefix

func WithDBPrefix(dbPrefix string) Option

WithDBPrefix is an option for adding a prefix to all created database names. No prefix will be used by default.

func WithLogger

func WithLogger(logger logger) Option

WithLogger is an option for specifying a custom logger. The standard Golang logger will be used by default.

func WithMaxRetries

func WithMaxRetries(maxRetries uint64) Option

WithMaxRetries is an option for specifying how many retries are allowed when there are certain transient errors from MongoDB. These transient errors can happen in two situations:

  1. An index conflict error when setting indexes via the SetStoreConfig method from multiple MongoDB Provider objects that look at the same stores (which might happen if you have multiple running instances of a service).
  2. If you're using MongoDB 4.0.0 (or DocumentDB 4.0.0), a "dup key" type of error when calling store.Put or store.Batch from multiple MongoDB Provider objects that look at the same stores.

maxRetries must be > 0. If not set (or set to an invalid value), it will default to 3.

func WithTimeBetweenRetries

func WithTimeBetweenRetries(timeBetweenRetries time.Duration) Option

WithTimeBetweenRetries is an option for specifying how long to wait between retries when there are certain transient errors from MongoDB. These transient errors can happen in two situations:

  1. An index conflict error when setting indexes via the SetStoreConfig method from multiple MongoDB Provider objects that look at the same stores (which might happen if you have multiple running instances of a service).
  2. If you're using MongoDB 4.0.0 (or DocumentDB 4.0.0), a "dup key" type of error when calling store.Put or store.Batch multiple times in parallel on the same key.

Defaults to two seconds if not set.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout is an option for specifying the timeout for all calls to MongoDB. The timeout is 10 seconds by default.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider represents a MongoDB/DocumentDB implementation of the storage.Provider interface.

func NewProvider

func NewProvider(connString string, caFilePath string, opts ...Option) (*Provider, error)

NewProvider instantiates a new MongoDB Provider. connString is a connection string as defined in https://docs.mongodb.com/manual/reference/connection-string/. Note that options supported by the Go Mongo driver (and the names of them) may differ from the documentation above. Check the Go Mongo driver (go.mongodb.org/mongo-driver/mongo) to make sure the options you're specifying are supported and will be captured correctly. If using DocumentDB, the retryWrites option must be set to false in the connection string (retryWrites=false) in order for it to work.

func (*Provider) Close

func (p *Provider) Close() error

Close closes all stores created under this store provider.

func (*Provider) GetOpenStores

func (p *Provider) GetOpenStores() []storage.Store

GetOpenStores returns all Stores currently open in this Provider.

func (*Provider) GetStoreConfig

func (p *Provider) GetStoreConfig(name string) (storage.StoreConfiguration, error)

GetStoreConfig gets the current Store configuration. If the underlying database for the given name has never been created by a call to OpenStore at some point, then an error wrapping ErrStoreNotFound will be returned. This method will not open a store in the Provider. If name is blank, then an error will be returned.

func (*Provider) OpenStore

func (p *Provider) OpenStore(name string) (storage.Store, error)

OpenStore opens a Store with the given name and returns a handle. If the underlying database for the given name has never been created before, then it is created. Store names are not case-sensitive. If name is blank, then an error will be returned.

func (*Provider) SetStoreConfig

func (p *Provider) SetStoreConfig(storeName string, config storage.StoreConfiguration) error

SetStoreConfig sets the configuration on a store. Indexes are created based on the tag names in config. This allows the store.Query method to operate faster. Existing tag names/indexes in the store that are not in the config passed in here will be removed. The store must already be open in this provider from a prior call to OpenStore. The name parameter cannot be blank.

Jump to

Keyboard shortcuts

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