mongo

package
v1.32.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: AGPL-3.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// User is the name of the config variable for a client connection
	User = "user"
	// Pass is the name of the config variable for a client connection
	Pass = "pass"
	// Host is the name of the config variable for a client connection
	Host = "host"
	// Port is the name of the config variable for a client connection
	Port = "port"
	// DBName is the name of the config variable for a client connection
	DBName = "db_name"
)

Variables

This section is empty.

Functions

func NewMongoDatabaseClient

func NewMongoDatabaseClient(
	config database.DatabaseConfiguration,
) (database.DatabaseClient, error)

NewMongoDatabaseClient creates a new instance of DatabaseClient to connect with Mongo databases

Types

type MongoDatabaseClient

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

MongoDatabaseClient defines a handler to manage actions against Mongo databases

func (*MongoDatabaseClient) Connect

func (repo *MongoDatabaseClient) Connect(
	ctx context.Context,
	timeout time.Duration,
) (err error)

Disconnect performs any action to proper connect and create a connection with the database

func (*MongoDatabaseClient) Count added in v1.31.0

func (repo *MongoDatabaseClient) Count(
	ctx context.Context,
	collection string,
	qb query.QueryBuilder,
) (uint64, error)

Count returns the number of records in the table/collection

func (*MongoDatabaseClient) DeleteOne

func (repo *MongoDatabaseClient) DeleteOne(
	ctx context.Context,
	collection string,
	qb query.QueryBuilder,
) error

DeleteOne deletes a single record in database

func (*MongoDatabaseClient) Disconnect

func (repo *MongoDatabaseClient) Disconnect(ctx context.Context) error

Disconnect performs any action to proper disconnect and close any connection with the database

func (*MongoDatabaseClient) Find

func (repo *MongoDatabaseClient) Find(
	ctx context.Context,
	collection string,
	qb query.QueryBuilder,
	target interface{},
) error

Find returns multiple records from the database

func (*MongoDatabaseClient) FindOne

func (repo *MongoDatabaseClient) FindOne(
	ctx context.Context,
	collection string,
	qb query.QueryBuilder,
	target interface{},
) error

FindOne fetches a single record in database

func (*MongoDatabaseClient) InsertOne

func (repo *MongoDatabaseClient) InsertOne(
	ctx context.Context,
	collection string,
	payload interface{},
) (string, error)

InsertOne stores a single record in database and returns the id of the stored record

func (*MongoDatabaseClient) UpdateOne

func (repo *MongoDatabaseClient) UpdateOne(
	ctx context.Context,
	collection string,
	qb query.QueryBuilder,
	payload interface{},
) error

UpdateOne updates a single record in database

type ObjectID

type ObjectID primitive.ObjectID

ObjectID is a wrapper for the original primitive.ObjectID

func NewObjectID

func NewObjectID() *ObjectID

NewObjectID generates a new ObjectID.

func NewObjectIDFromHex

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

func (o *ObjectID) Hex() string

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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