mongodb

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(ctx context.Context, col string, query []bson.M, value interface{}) error

func Count

func Count(ctx context.Context, col string) (int64, error)

func CountWithFilter

func CountWithFilter(ctx context.Context, col string, filter interface{}) (int64, error)

func CountWithQuery

func CountWithQuery(ctx context.Context, col string, query any) (int, error)

func DeleteOne

func DeleteOne(ctx context.Context, col string, query bson.M) (mongo.DeleteResult, error)

func FindOne

func FindOne(ctx context.Context, col string, query bson.M, value interface{}) error

func GetMongoClient added in v0.0.13

func GetMongoClient() *mongo.Client

func GetMongoDb

func GetMongoDb() *mongo.Database

GetMongoDb function returns a pointer to the `mongo.Database` instance used to communicate with MongoDB server. The function simply returns the MongoDB client instance stored in a `mongodb` singleton object. This function is used to obtain the MongoDB client connection in other parts of the application.

func Init

func Init(cp DatabaseCredentialHelper, host string, port string, database string)

Initializes the mongodb client

func InsertOne

func InsertOne(ctx context.Context, col string, input interface{}) (mongo.InsertOneResult, error)

func Ping

func Ping() bool

Ping the mongodb database and returns the result as a bool

func UpdateOne

func UpdateOne(ctx context.Context, col string, filter bson.M, update bson.M) (mongo.UpdateResult, error)

Types

type DatabaseCredentialHelper

type DatabaseCredentialHelper interface {
	GetCredentials() (string, string)
	CheckAndRenew() bool
}

type MongodbCon added in v0.3.0

type MongodbCon struct {
	Client      *mongo.Client
	Context     context.Context
	Credentials DatabaseCredentialHelper
	Host        string
	Port        string
	Database    string
}

This type implements the mongodb connection in ror

func GetMongodbConnection added in v0.3.0

func GetMongodbConnection() *MongodbCon

func (MongodbCon) Aggregate added in v0.3.0

func (rc MongodbCon) Aggregate(ctx context.Context, col string, query []bson.M, value interface{}) error

func (MongodbCon) CheckHealth added in v0.3.0

func (rc MongodbCon) CheckHealth() []health.Check

CheckHealth checks the health of the redis connection and returns a health check

func (MongodbCon) Count added in v0.3.0

func (rc MongodbCon) Count(ctx context.Context, col string) (int64, error)

func (MongodbCon) CountWithFilter added in v0.3.0

func (rc MongodbCon) CountWithFilter(ctx context.Context, col string, filter interface{}) (int64, error)

func (MongodbCon) CountWithQuery added in v0.3.0

func (rc MongodbCon) CountWithQuery(ctx context.Context, col string, query any) (int, error)

func (MongodbCon) DeleteOne added in v0.3.0

func (rc MongodbCon) DeleteOne(ctx context.Context, col string, query bson.M) (mongo.DeleteResult, error)

func (MongodbCon) FindOne added in v0.3.0

func (rc MongodbCon) FindOne(ctx context.Context, col string, query bson.M, value interface{}) error

func (MongodbCon) GenerateAggregateQuery added in v0.3.0

func (rc MongodbCon) GenerateAggregateQuery(rorResourceQuery *rorresources.ResourceQuery) []bson.M

func (MongodbCon) GetMongoDb added in v0.3.0

func (rc MongodbCon) GetMongoDb() *mongo.Database

func (MongodbCon) InsertOne added in v0.3.0

func (rc MongodbCon) InsertOne(ctx context.Context, col string, input interface{}) (mongo.InsertOneResult, error)

func (MongodbCon) UpdateOne added in v0.3.0

func (rc MongodbCon) UpdateOne(ctx context.Context, col string, filter bson.M, update bson.M) (mongo.UpdateResult, error)

func (MongodbCon) UpsertOne added in v0.3.0

func (rc MongodbCon) UpsertOne(ctx context.Context, col string, filter bson.M, update interface{}) (mongo.UpdateResult, error)

Jump to

Keyboard shortcuts

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