mongo

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoService

type MongoService struct {
	Address string
	Conn    *mongo.Client
	// contains filtered or unexported fields
}

func Init

func Init(address string) (*MongoService, error)

func (*MongoService) Close

func (m *MongoService) Close() error

func (*MongoService) GetCollection

func (m *MongoService) GetCollection(databaseName string, collectionName string) (interface{}, error)

MUST handle error!

Convert return interface into specific model ("models.Test" for example):

collectionInterface, err := mongoService.GetCollection(DatabaseName, models.TestCollectionName)
if err != nil {
	t.Errorf("%v", err)
	return
}
collection := collectionInterface.(*mongo.MyCollection[models.Test])

type MyCollection

type MyCollection[T any] struct {
	// contains filtered or unexported fields
}

func (*MyCollection[T]) DeleteMany

func (m *MyCollection[T]) DeleteMany(filter bson.M, opts ...*options.DeleteOptions) error

func (*MyCollection[T]) DeleteOne

func (m *MyCollection[T]) DeleteOne(filter bson.M, opts ...*options.DeleteOptions) error

func (*MyCollection[T]) Find

func (m *MyCollection[T]) Find(filter bson.D, opts ...*options.FindOptions) (result []T, err error)

MUST handle error!

func (*MyCollection[T]) FindOneByIdString

func (m *MyCollection[T]) FindOneByIdString(id string) (result T, err error)

MUST handle error!

func (*MyCollection[T]) FindOneByObjectId

func (m *MyCollection[T]) FindOneByObjectId(id primitive.ObjectID) (result T, err error)

MUST handle error!

func (*MyCollection[T]) InsertMany

func (m *MyCollection[T]) InsertMany(document []T) error

MUST handle error!

func (*MyCollection[T]) InsertOne

func (m *MyCollection[T]) InsertOne(document T) error

MUST handle error!

func (*MyCollection[T]) UpdateMany

func (m *MyCollection[T]) UpdateMany(filter bson.M, update bson.M, opts ...*options.UpdateOptions) error

MUST handle error!

func (*MyCollection[T]) UpdateOne

func (m *MyCollection[T]) UpdateOne(filter bson.M, update bson.M, opts ...*options.UpdateOptions) error

MUST handle error!

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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