db

package
v0.0.0-...-6fa6eff Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDocuments record not found error
	ErrNoDocuments error = mongo.ErrNoDocuments
	// DefaultTimeout is the default timeout for any interaction with the Mongo DB
	DefaultTimeout = 5 * time.Second
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Health(context.Context) error
	Disconnect(context.Context)
	Collection(name string, opts ...*options.CollectionOptions) Collection
}

Client represents the client to interact with a Mongo DB

func NewClient

func NewClient(ctx context.Context, conf Config) (Client, error)

NewClient creates a new database connection

type Collection

type Collection interface {
	InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) Result
	Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
}

Collection is the interface to interact with a mongo collection

type Config

type Config struct {
	URI string
	DB  string

	Timeout time.Duration
}

Config holds database configuration

type Result

type Result interface {
	Decode(v interface{}) error
}

Result is the interface to interact with Query results

Jump to

Keyboard shortcuts

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