mongodb

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client *mongo.Client
View Source
var Database *mongo.Database

Functions

func Connect

func Connect() error

Connect initializes the MongoDB client using the MONGODB_URI environment variable.

func Disconnect

func Disconnect() error

Disconnect closes the connection to the MongoDB client.

func GenerateCustomNanoID added in v0.0.6

func GenerateCustomNanoID(alphabets string, size int) string

func GenerateMongoID added in v0.0.5

func GenerateMongoID() bson.ObjectID

func GenerateNanoID added in v0.0.5

func GenerateNanoID() string

func GenerateNanoIdBySize added in v0.0.6

func GenerateNanoIdBySize(size int) string

Types

type MongoConfig

type MongoConfig struct {
	Username string
	Password string
	Host     string
	Port     string
	Database string
	URI      string
	URIQuery string
}
var Config MongoConfig = MongoConfig{
	Username: "",
	Password: "",
	Host:     "",
	Port:     "",
	Database: "",
	URIQuery: "",
	URI:      "",
}

type ODM added in v0.0.2

type ODM[T any] struct {
	Collection *mongo.Collection
	CreateOne  func(doc T, opts ...options.Lister[options.InsertOneOptions]) (*mongo.InsertOneResult, error)
	CreateMany func(docs []T, opts ...options.Lister[options.InsertManyOptions]) (*mongo.InsertManyResult, error)
	BulkWrite  func(models []mongo.WriteModel) (*mongo.BulkWriteResult, error)
	FindOne    func(filter bson.M, opts ...options.Lister[options.FindOneOptions]) (*T, error)
	FindMany   func(filter bson.M, opts ...options.Lister[options.FindOptions]) ([]T, error)
	FindById   func(id string, opts ...options.Lister[options.FindOneOptions]) (*T, error)
	List       func(opts ...options.Lister[options.FindOptions]) ([]T, error)
	Count      func(filter bson.M, opts ...options.Lister[options.CountOptions]) (int64, error)
	UpdateOne  func(filter bson.M, update bson.M, opts ...options.Lister[options.UpdateOneOptions]) (*mongo.UpdateResult, error)
	UpdateMany func(filter bson.M, update bson.M, opts ...options.Lister[options.UpdateManyOptions]) (*mongo.UpdateResult, error)
	UpdateById func(id string, update bson.M, opts ...options.Lister[options.UpdateOneOptions]) (*mongo.UpdateResult, error)
	DeleteOne  func(filter bson.M, opts ...options.Lister[options.DeleteOneOptions]) (*mongo.DeleteResult, error)
	DeleteMany func(filter bson.M, opts ...options.Lister[options.DeleteManyOptions]) (*mongo.DeleteResult, error)
	DeleteById func(id string, opts ...options.Lister[options.DeleteOneOptions]) (*mongo.DeleteResult, error)
}

func NewODM added in v0.0.2

func NewODM[T any](collection *mongo.Collection) *ODM[T]

Jump to

Keyboard shortcuts

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