mongo

package
v1.26.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrNoDocuments added in v1.24.0

func IsErrNoDocuments(err error) bool

IsErrNoDocuments checks if the error is actually the mongo.ErrNoDocuments

Types

type DefaultMongoClient

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

DefaultMongoClient defines the default and basic handler to manage actions

with Mongo database

func (*DefaultMongoClient) Aggregate

func (m *DefaultMongoClient) Aggregate(
	ctx context.Context,
	filters []interface{},
	decoder interface{},
) error

Aggregate executes an aggregate command

func (*DefaultMongoClient) DeleteOne

func (m *DefaultMongoClient) DeleteOne(
	ctx context.Context,
	filter interface{},
) error

DeleteOne deletes a single record in database

func (*DefaultMongoClient) Find

func (m *DefaultMongoClient) Find(
	ctx context.Context,
	queryBuilder query.QueryBuilder,
	decoder interface{},
) error

Find returns multiple records from the database

func (*DefaultMongoClient) FindOne

func (m *DefaultMongoClient) FindOne(
	ctx context.Context,
	queryBuilder query.QueryBuilder,
	decoder interface{},
) error

FindOne fetches a single record in database

func (*DefaultMongoClient) InsertOne

func (m *DefaultMongoClient) InsertOne(
	ctx context.Context,
	filter interface{},
) (string, error)

InsertOne stores a single record in database

func (*DefaultMongoClient) ReplaceOne

func (m *DefaultMongoClient) ReplaceOne(
	ctx context.Context,
	queryBuilder query.QueryBuilder,
	payload interface{},
) error

ReplaceOne replaces an entire record in database

func (*DefaultMongoClient) SetCollection

func (m *DefaultMongoClient) SetCollection(collection string)

SetCollection sets the name of the collection

where actions will be performed

func (*DefaultMongoClient) UpdateOne

func (m *DefaultMongoClient) UpdateOne(
	ctx context.Context,
	filter interface{},
	payload interface{},
) error

UpdateOne updates a single record in database

type DefaultMongoConfig

type DefaultMongoConfig struct {
	DBName string
	// contains filtered or unexported fields
}

DefaultMongoConfig defines the default and basic configuration to manage actions

with Mongo database

func (DefaultMongoConfig) GetConnUrl

func (mc DefaultMongoConfig) GetConnUrl() string

GetConnUrl returns the URL of the database

func (DefaultMongoConfig) GetDBName

func (mc DefaultMongoConfig) GetDBName() string

GetDBName returns the name of the DB

type MongoClient

type MongoClient interface {
	// SetCollection sets the name of the collection
	//  where actions will be performed
	SetCollection(string)
	// Aggregate executes an aggregate command
	Aggregate(
		ctx context.Context,
		filters []interface{},
		decoder interface{},
	) error
	// Find returns multiple records from the database
	Find(
		ctx context.Context,
		queryBuilder query.QueryBuilder,
		decoder interface{},
	) error
	// FindOne fetches a single record in database
	FindOne(
		ctx context.Context,
		queryBuilder query.QueryBuilder,
		decoder interface{},
	) error
	// InsertOne stores a single record in database
	//  and returns the id of the stored record
	InsertOne(
		ctx context.Context,
		filter interface{},
	) (string, error)
	// UpdateOne updates a single record in database
	UpdateOne(
		ctx context.Context,
		filter interface{},
		payload interface{},
	) error
	// ReplaceOne replaces an entire record in database
	ReplaceOne(
		ctx context.Context,
		queryBuilder query.QueryBuilder,
		payload interface{},
	) error
	// DeleteOne deletes a single record in database
	DeleteOne(
		ctx context.Context,
		filter interface{},
	) error
}

MongoClient defines a handler to manage actions with Mongo database

func NewDefaultMongoClient

func NewDefaultMongoClient(
	mongoConfig MongoConfig,
	collection string,
) (MongoClient, error)

NewDefaultMongoClient returns an instance of MongoClient

type MongoConfig

type MongoConfig interface {
	// GetConnUrl returns the URL of the database
	GetConnUrl() string
	// GetDBName returns the name of the DB
	GetDBName() string
}

MongoConfig defines all data required to connect with a Mongo database

func NewDefaultMongoConfig

func NewDefaultMongoConfig(
	connUrl string,
	DBName string,
) MongoConfig

NewDefaultMongoConfig creates an instance of MongoConfig

type ObjectID added in v1.23.0

type ObjectID primitive.ObjectID

ObjectID is a wrapper for the original primitive.ObjectID

func NewObjectID added in v1.23.0

func NewObjectID() *ObjectID

NewObjectID generates a new ObjectID.

func NewObjectIDFromHex added in v1.23.0

func NewObjectIDFromHex(hex string) (*ObjectID, error)

ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.

func (*ObjectID) Hex added in v1.23.0

func (o *ObjectID) Hex() string

Hex returns the hex encoding of the ObjectID as a string.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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