mango

package module
v0.0.0-...-bd61050 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IMongoData

type IMongoData interface {
	GetID() interface{}
}

IMongoData is interface must be implemented by all models that need to save in MongoDB

type MongoConfig

type MongoConfig struct {
	Host        string
	Port        int
	DbName      string
	User        string
	Pwd         string
	ConnTimeout int // in seconds
}

MongoConfig is config for mongodb connection

type MongoSession

type MongoSession struct {
	*mongo.Client
	DBname string
}

MongoSession holds session for mongodb connection

func InitSession

func InitSession(config MongoConfig) *MongoSession

InitSession initialize mongodb session

func (*MongoSession) Cleanup

func (m *MongoSession) Cleanup()

Cleanup closes existing mongodb session

func (*MongoSession) DeleteSingle

func (m *MongoSession) DeleteSingle(col *mongo.Collection, id interface{}) error

DeleteSingle removes single document by ID

func (*MongoSession) DeleteSingleContext

func (m *MongoSession) DeleteSingleContext(ctx context.Context, col *mongo.Collection, id interface{}) error

DeleteSingleContext removes single document by ID

func (*MongoSession) GetColl

func (m *MongoSession) GetColl(collname string) *mongo.Collection

GetColl gives collection as specified

func (*MongoSession) InsertBulk

func (m *MongoSession) InsertBulk(col *mongo.Collection, data ...interface{}) error

InsertBulk inserts multiple documents at once, if document already exist, error will be raised

func (*MongoSession) InsertBulkContext

func (m *MongoSession) InsertBulkContext(ctx context.Context, col *mongo.Collection, data ...interface{}) error

InsertBulkContext inserts multiple documents at once, if document already exist, error will be raised

func (*MongoSession) SaveSingle

func (m *MongoSession) SaveSingle(col *mongo.Collection, data IMongoData) error

SaveSingle insert or update single document by ID

func (*MongoSession) SaveSingleContext

func (m *MongoSession) SaveSingleContext(ctx context.Context, col *mongo.Collection, data IMongoData) error

SaveSingleContext insert or update single document by ID

Jump to

Keyboard shortcuts

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