mongodb

package
v0.0.0-...-c8e7285 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const Err11000DupKeyError = 11000

Err11000DupKeyError code error for E11000.

Variables

This section is empty.

Functions

func Find

func Find(ctx context.Context, filter bson.M, collection *mongo.Collection, dtos interface{}) error

Find executes the query in MongoDB and decode all results in dtos slice. Example: var dtos []userDTO err := mongodb.Find(ctx, props, m.collection, &dtos).

func IsDuplKeyError

func IsDuplKeyError(err error) bool

IsDuplKeyError detects if the error is a E11000 duplicate key error.

Types

type MongoDB

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

MongoDB will manage the connection with the database.

func NewMongoDB

func NewMongoDB(logger logging.Logger) *MongoDB

NewMongoDB is a constructor function.

func (*MongoDB) Connect

func (m *MongoDB) Connect(uri string) (*mongo.Client, error)

Connect open a database connection and check if it is connecting using ping.

func (*MongoDB) Disconnect

func (m *MongoDB) Disconnect()

Disconnect closes the connection with the database.

Jump to

Keyboard shortcuts

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