mongodb

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MongoDBPingInterval mongodb heatbeat ping interval
	MongoDBPingInterval = 5
)

Constant

Variables

This section is empty.

Functions

func AddMongoBeforeSaveObserver

func AddMongoBeforeSaveObserver(f MongoBeforeSaveFunc)

AddMongoBeforeSaveObserver observer

func GetCollectionName

func GetCollectionName(dst interface{}) string

GetCollectionName get collection name by model

func GetMetaField

func GetMetaField(model interface{}) (reflect.StructField, bool)

GetMetaField get meta field by model

func GetModelPk

func GetModelPk(model interface{}) reflect.Value

GetModelPk get model pk

func InitMongoDB

func InitMongoDB(dbConfigs map[string]definations.DBConnectorConfig) error

InitMongoDB initialzie mongodb sessions

Types

type ErrorMongoDB

type ErrorMongoDB string

ErrorMongoDB mongodb error

func (ErrorMongoDB) Error

func (s ErrorMongoDB) Error() string

Error error message for mongodb error

type MongoBeforeSaveFunc

type MongoBeforeSaveFunc func(v interface{})

MongoBeforeSaveFunc mongodb before save event callback

type MongoCollectionIndex

type MongoCollectionIndex struct {
	Fields []string
	Unique bool
}

MongoCollectionIndex struct

func PrepareCollectionIndexes

func PrepareCollectionIndexes(dst interface{}) []MongoCollectionIndex

PrepareCollectionIndexes prepare indexes

type MongoMeta

type MongoMeta struct {
	// contains filtered or unexported fields
}

MongoMeta mongodb models meta structure

type MongoSession

type MongoSession struct {
	Client    *mongo.Client
	Database  string
	LastError error
	Name      string
	// contains filtered or unexported fields
}

MongoSession mongodb session

func GetMongoDB

func GetMongoDB(name string) *MongoSession

GetMongoDB get mongodb

func (*MongoSession) DeleteOne

func (s *MongoSession) DeleteOne(dst interface{}, isInsert bool) error

DeleteOne delete

func (*MongoSession) FindAll

func (s *MongoSession) FindAll(collectionName string, filter bson.D) []bson.M

FindAll finder

func (*MongoSession) FindOne

func (s *MongoSession) FindOne(dst interface{}, filter interface{}, opts ...*options.FindOneOptions) error

FindOne finder

func (*MongoSession) GetCollection

func (s *MongoSession) GetCollection(collectionName string) *mongo.Collection

GetCollection get mongodb collection

func (*MongoSession) IsMongoDBReady

func (s *MongoSession) IsMongoDBReady() bool

IsMongoDBReady is ready

func (*MongoSession) MongoDBInsertMany

func (s *MongoSession) MongoDBInsertMany(collectionName string, docs []interface{}) bool

MongoDBInsertMany insert many

func (*MongoSession) Ping

func (s *MongoSession) Ping() error

Ping pinger

func (*MongoSession) QueryFind

func (s *MongoSession) QueryFind(model interface{}, filter interface{}, limit int64, results interface{}) (int, error)

QueryFind query

func (*MongoSession) QueryMaxID

func (s *MongoSession) QueryMaxID(model interface{}, result interface{}, aggField string) error

QueryMaxID query max id

func (*MongoSession) SaveOne

func (s *MongoSession) SaveOne(dst interface{}, isInsert bool) error

SaveOne save

func (*MongoSession) StartKeepAlive

func (s *MongoSession) StartKeepAlive()

StartKeepAlive keepalive

Jump to

Keyboard shortcuts

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