mongodb

package
v0.0.0-...-be61b1a Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	MongoDB *mongo.Client
}

func ConnectToMongoDB

func ConnectToMongoDB(mongoDBClientConfig *ClientConfigData) (*Client, error)

func (*Client) CountDocumentsInMongo

func (client *Client) CountDocumentsInMongo(databaseName string, collection string, result interface{}) (int, error)

func (*Client) CreateNewCollection

func (client *Client) CreateNewCollection(databaseName, collectionName string) error

func (*Client) CreateUniqueIndex

func (client *Client) CreateUniqueIndex(collectionName string, databaseName string, fieldName string, unique bool) error

func (*Client) DeleteCollectionMongo

func (client *Client) DeleteCollectionMongo(databaseName string, collection string) error

func (*Client) DeleteDocumentMongo

func (client *Client) DeleteDocumentMongo(databaseName string, filter bson.M, collection string) (interface{}, error)

func (*Client) FindManyInMongo

func (client *Client) FindManyInMongo(databaseName string, filter bson.M, collection string, sort bson.D, result interface{}) error

func (*Client) FindOneInMongo

func (client *Client) FindOneInMongo(databaseName string, filter bson.M, collection string, sort bson.D, result interface{}) (foundOne bool, err error)

func (*Client) InsertOneToMongo

func (client *Client) InsertOneToMongo(databaseName string, data interface{}, collection string) (string, error)

func (*Client) IsValueInCollection

func (client *Client) IsValueInCollection(databaseName, collectionName, fieldName, fieldValue string) (bool, error)

Check if value for field name (key) exists in collection (eg. is email address xyz already registered)

func (*Client) StartSession

func (client *Client) StartSession() (session mongo.Session, err error)

func (*Client) UpdateOneInMongo

func (client *Client) UpdateOneInMongo(databaseName string, filter bson.M, update bson.M, collection string) (*mongo.UpdateResult, error)

type ClientConfigData

type ClientConfigData struct {
	Scheme   string
	Username string
	Password string
	Host     string
	Port     string
}

func ClientConfig

func ClientConfig() (mongoDBClientConfig *ClientConfigData, err error)

Retrieve configuration data (eg.host, port, etc.) from .env file for production settings only Base parameter for dependency injection of mongodb client (production)

func (*ClientConfigData) GetURI

func (mongoDBClientConfig *ClientConfigData) GetURI() (string, error)

GetURI returns the MongoDB connection URI based on the configuration.

type MethodInterface

type MethodInterface struct {
	RepositoryInterface Repository
}

func NewMongoDBMethodInterface

func NewMongoDBMethodInterface(mongoClient *Client) *MethodInterface

type Repository

type Repository interface {
	InsertOneToMongo(databaseName string, data interface{}, collection string) (string, error)
	IsValueInCollection(databaseName string, collectionName string, fieldName, fieldValue string) (bool, error)
	UpdateOneInMongo(databaseName string, filter bson.M, update bson.M, collection string) (*mongo.UpdateResult, error)
	FindOneInMongo(databaseName string, filter bson.M, collection string, sort bson.D, result interface{}) (foundOne bool, err error)
	FindManyInMongo(databaseName string, filter bson.M, collection string, sort bson.D, result interface{}) error
	DeleteDocumentMongo(databaseName string, filter bson.M, collection string) (interface{}, error)
	DeleteCollectionMongo(databaseName string, collection string) error
	CreateNewCollection(databaseName, collectionName string) error
	CountDocumentsInMongo(databaseName string, collection string, result interface{}) (int, error)
	CreateUniqueIndex(collectionName string, databaseName string, fieldName string, unique bool) error
	StartSession() (session mongo.Session, err error)
}

////////////////////////////////////////////////////////////////////// Setup interface for database repository utilizing Dependency Injection ///////////////////

Jump to

Keyboard shortcuts

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