mongodb

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterArgs

func FilterArgs(filter bson.M) *logutils.FieldArgs

FilterArgs creates a log object from an unordered MongoDB filter document

func PerformTransaction

func PerformTransaction[T common.Storage](th TransactionHandler[T], transaction func(storage T) error) error

PerformTransaction performs a transaction

Types

type Adapter

type Adapter struct {
	Context mongo.SessionContext
	// contains filtered or unexported fields
}

Adapter implements the Storage interface

func NewStorageAdapter

func NewStorageAdapter(db *Database, configDataParser func(*common.Config) error) *Adapter

NewStorageAdapter creates a new storage adapter instance

func (*Adapter) DeleteConfig

func (a *Adapter) DeleteConfig(id string) error

DeleteConfig deletes a configuration from storage

func (*Adapter) FindConfig

func (a *Adapter) FindConfig(configType string, appID string, orgID string) (*common.Config, error)

FindConfig finds the config for the specified type, appID, and orgID

func (*Adapter) FindConfigByID

func (a *Adapter) FindConfigByID(id string) (*common.Config, error)

FindConfigByID finds the config for the specified ID

func (*Adapter) FindConfigs

func (a *Adapter) FindConfigs(configType *string) ([]common.Config, error)

FindConfigs finds all configs for the specified type

func (*Adapter) InsertConfig

func (a *Adapter) InsertConfig(config common.Config) error

InsertConfig inserts a new config

func (*Adapter) NewStorageListener

func (a *Adapter) NewStorageListener() StorageListener

NewStorageListener creates a new StorageListener

func (*Adapter) RegisterStorageListener

func (a *Adapter) RegisterStorageListener(listener common.StorageListener)

RegisterStorageListener registers a data change listener with the storage adapter

func (*Adapter) Start

func (a *Adapter) Start(sl common.StorageListener) error

Start starts the storage

func (*Adapter) StartSession

func (a *Adapter) StartSession(opts ...*options.SessionOptions) (mongo.Session, error)

StartSession starts a new session on the underlying MongoDB database

func (*Adapter) UpdateConfig

func (a *Adapter) UpdateConfig(config common.Config) error

UpdateConfig updates an existing config

func (*Adapter) WithContext

func (a *Adapter) WithContext(context mongo.SessionContext) common.Storage

WithContext creates a new Adapter with provided context

type CollectionWrapper

type CollectionWrapper struct {
	Database *Database
	Coll     *mongo.Collection
}

CollectionWrapper wraps a MongoDB collection with additional database settings

func (*CollectionWrapper) AddIndex

func (collWrapper *CollectionWrapper) AddIndex(ctx context.Context, keys interface{}, unique bool) error

AddIndex performs an AddIndex operation on the underlying MongoDB collection

func (*CollectionWrapper) AddIndexWithOptions

func (collWrapper *CollectionWrapper) AddIndexWithOptions(ctx context.Context, keys interface{}, opt *options.IndexOptions) error

AddIndexWithOptions performs an AddIndexWithOptions operation on the underlying MongoDB collection

func (*CollectionWrapper) Aggregate

func (collWrapper *CollectionWrapper) Aggregate(ctx context.Context, pipeline interface{}, result interface{}, ops *options.AggregateOptions) error

Aggregate performs an Aggregate operation on the underlying MongoDB collection

func (*CollectionWrapper) CountDocuments

func (collWrapper *CollectionWrapper) CountDocuments(ctx context.Context, filter interface{}) (int64, error)

CountDocuments performs a CountDocuments operation on the underlying MongoDB collection

func (*CollectionWrapper) DeleteMany

func (collWrapper *CollectionWrapper) DeleteMany(ctx context.Context, filter interface{}, opts *options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteMany performs a Delete operation on the underlying MongoDB collection

func (*CollectionWrapper) DeleteOne

func (collWrapper *CollectionWrapper) DeleteOne(ctx context.Context, filter interface{}, opts *options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOne performs a DeleteOne operation on the underlying MongoDB collection

func (*CollectionWrapper) Drop

func (collWrapper *CollectionWrapper) Drop(ctx context.Context) error

Drop performs a Drop operation on the underlying MongoDB collection

func (*CollectionWrapper) DropIndex

func (collWrapper *CollectionWrapper) DropIndex(ctx context.Context, name string) error

DropIndex performs a DropIndex operation on the underlying MongoDB collection

func (*CollectionWrapper) Find

func (collWrapper *CollectionWrapper) Find(ctx context.Context, filter interface{}, result interface{},
	findOptions *options.FindOptions) error

Find performs a Find operation on the underlying MongoDB collection

func (*CollectionWrapper) FindOne

func (collWrapper *CollectionWrapper) FindOne(ctx context.Context, filter interface{}, result interface{}, findOptions *options.FindOneOptions) error

FindOne performs a FindOne operation on the underlying MongoDB collection

func (*CollectionWrapper) FindOneAndUpdate

func (collWrapper *CollectionWrapper) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, result interface{}, opts *options.FindOneAndUpdateOptions) error

FindOneAndUpdate performs a FindOneAndUpdate operation on the underlying MongoDB collection

func (*CollectionWrapper) InsertMany

func (collWrapper *CollectionWrapper) InsertMany(ctx context.Context, documents []interface{}, opts *options.InsertManyOptions) (*mongo.InsertManyResult, error)

InsertMany performs an InsertMany operation on the underlying MongoDB collection

func (*CollectionWrapper) InsertOne

func (collWrapper *CollectionWrapper) InsertOne(ctx context.Context, data interface{}) (interface{}, error)

InsertOne performs an InsertOne operation on the underlying MongoDB collection

func (*CollectionWrapper) ListIndexes

func (collWrapper *CollectionWrapper) ListIndexes(ctx context.Context, l *logs.Logger) ([]bson.M, error)

ListIndexes performs a ListIndexes operation on the underlying MongoDB collection

func (*CollectionWrapper) ReplaceOne

func (collWrapper *CollectionWrapper) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, replaceOptions *options.ReplaceOptions) error

ReplaceOne performs a ReplaceOne operation on the underlying MongoDB collection

func (*CollectionWrapper) UpdateMany

func (collWrapper *CollectionWrapper) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts *options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateMany performs an UpdateMany operation on the underlying MongoDB collection

func (*CollectionWrapper) UpdateOne

func (collWrapper *CollectionWrapper) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts *options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOne performs an UpdateOne operation on the underlying MongoDB collection

func (*CollectionWrapper) Watch

func (collWrapper *CollectionWrapper) Watch(pipeline interface{}, l *logs.Logger)

Watch performs a Watch operation on the underlying MongoDB collection

type Database

type Database struct {
	MongoDBAuth  string
	MongoDBName  string
	MongoTimeout time.Duration
	Logger       *logs.Logger

	OnDataChanged func(string)
	Listeners     []common.StorageListener
	// contains filtered or unexported fields
}

Database represents a wrapper for a connection to a MongoDB instance

func (*Database) Collection

func (d *Database) Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection

Collection gets a handle for a MongoDB collection with the given name configured with the given CollectionOptions

type StorageListener

type StorageListener struct {
	common.DefaultStorageListener
	// contains filtered or unexported fields
}

StorageListener handles responding to database changes

func (*StorageListener) OnConfigsUpdated

func (s *StorageListener) OnConfigsUpdated()

OnConfigsUpdated handles database updates to configs

type TransactionHandler

type TransactionHandler[T common.Storage] interface {
	WithContext(context mongo.SessionContext) T
	StartSession(opts ...*options.SessionOptions) (mongo.Session, error)
}

TransactionHandler represents an entity that is able to handle a transaction on a MongoDB database

Jump to

Keyboard shortcuts

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