mongo

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseMongoRepository

type BaseMongoRepository interface {
	db.BaseRepository
	// Database return current mongo database
	Database() *mongo.Database
	// GetCollection returns reference to mongo.Collection (table)
	GetCollection(name string) *mongo.Collection
	// InsertOne executes an insert command to insert a single document into the collection.
	InsertOne(ctx context.Context, coll *mongo.Collection, document interface{}) (string, error)
	// GetOne returns document looked up by filter, or error
	GetOne(ctx context.Context, coll *mongo.Collection, filter interface{}, document interface{}) error
	// GetOneByID returns document looked up by id, or error
	GetOneByID(ctx context.Context, coll *mongo.Collection, id string, document interface{}) error
	// Delete deletes a stored document(s) by provided filter
	Delete(ctx context.Context, coll *mongo.Collection, filter interface{}) error
	// DeleteByID deletes a stored document with provided id
	DeleteByID(ctx context.Context, coll *mongo.Collection, id string) error
	// Find returns all documents matching to the filter
	Find(ctx context.Context, coll *mongo.Collection, filter interface{}, docs interface{}) error
	// ReplaceOne replace a single document looked up by filter
	ReplaceOne(ctx context.Context, coll *mongo.Collection, filter interface{}, document interface{}) error
	// UpdateOne updates a fields in single document looked up by filter
	UpdateOne(ctx context.Context, coll *mongo.Collection, filter interface{}, update interface{}) error
	// Count returns count of documents looked up by filter
	Count(ctx context.Context, coll *mongo.Collection, filter interface{}) (int64, error)
}

BaseMongoRepository base MongoDb repository functionality

type DBResult

type DBResult map[string]interface{}

DBResult DB result from custom queries

type Db

type Db struct {
	Timeout time.Duration
	BaseMongoRepository
	// contains filtered or unexported fields
}

Db service managing connection to MongoDb instance

func NewMongoDB

func NewMongoDB(ctx context.Context, lgr logger.Logger, connectString string) (*Db, error)

NewMongoDB create a new Db instance, with the connection URI provided

func (*Db) Aggregate

func (db *Db) Aggregate(ctx context.Context, coll *mongo.Collection, pipe interface{}) ([]DBResult, error)

Aggregate execute custom aggregate query

func (*Db) Count

func (db *Db) Count(ctx context.Context, coll *mongo.Collection, filter interface{}) (int64, error)

Count returns count of documents looked up by filter

func (*Db) Database

func (db *Db) Database() *mongo.Database

Database return current mongo database

func (*Db) Delete

func (db *Db) Delete(ctx context.Context, coll *mongo.Collection, filter interface{}) error

Delete deletes a stored document(s) looked up by provided filter

func (*Db) DeleteByID

func (db *Db) DeleteByID(ctx context.Context, coll *mongo.Collection, id string) error

DeleteByID deletes a stored document

func (*Db) Disconnect

func (db *Db) Disconnect(ctx context.Context) error

Disconnect close sockets to DB

func (*Db) Find

func (db *Db) Find(ctx context.Context, coll *mongo.Collection, filter interface{}, docs interface{}) error

Find returns all documents matching to the filter

func (*Db) GetCollection

func (db *Db) GetCollection(name string) *mongo.Collection

GetCollection returns reference to mongo.Collection (table)

func (*Db) GetOne

func (db *Db) GetOne(ctx context.Context, coll *mongo.Collection, filter interface{}, document interface{}) error

GetOne returns document looked up by filter, or error

func (*Db) GetOneByID

func (db *Db) GetOneByID(ctx context.Context, coll *mongo.Collection, id string, document interface{}) error

GetOneByID returns document looked up by id, or error

func (*Db) InsertOne

func (db *Db) InsertOne(ctx context.Context, coll *mongo.Collection, document interface{}) (string, error)

InsertOne executes an insert command to insert a single document into the collection.

func (*Db) Ping

func (db *Db) Ping(ctx context.Context) error

Ping check connection to database

func (*Db) ReplaceOne

func (db *Db) ReplaceOne(ctx context.Context, coll *mongo.Collection, filter interface{}, document interface{}) error

ReplaceOne replace a single document looked up by filter

func (*Db) UpdateOne

func (db *Db) UpdateOne(ctx context.Context, coll *mongo.Collection, filter interface{}, update interface{}) error

UpdateOne updates a fields in single document looked up by filter

Jump to

Keyboard shortcuts

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