mongo

package
v0.0.0-...-ff80121 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseSession

func CloseSession()

CloseSession close mgo connection session

func Connection

func Connection() *mgo.Session

Connection return new mongodb connection. Usage:

conn := mongo.Connection()
defer conn.Close()
... do something ...

func DeleteById

func DeleteById(cName string, id string) (code int, err error)

DeleteById Delete a record by primary key ID

func FindAllByPage

func FindAllByPage(cName string, query bson.M, sort string, fields string, page int, limit int, r interface{}) (err error)

FindAllByPage Execute the query, Paginate to get data

func FindById

func FindById(cName string, id string, model interface{}, fields string) (code int, err error)

FindById Finding a record by primary key ID Usage: m := &mongo.Moment{} // NOTICE: please use ref mongo.FindById("collection name", "id", m)

func FindOne

func FindOne(cName string, query bson.M, model interface{}, fields string) (code int, err error)

FindOne

func InitMongo

func InitMongo() (err error)

func TransList2BsonM

func TransList2BsonM(ls []string) (bm bson.M)

TransMapToBsonM

func TransMap2BsonM

func TransMap2BsonM(mp map[string]interface{}) bson.M

TransMapToBsonM

func TransStruct2BsonM

func TransStruct2BsonM(obj interface{}) bson.M

TransStruct2BsonM translate structure to map

func UpdateBy

func UpdateBy(cName string, query bson.M, change bson.M) (code int, err error)

UpdateSome

func UpdateById

func UpdateById(cName string, id string, change bson.M) (code int, err error)

UpdateById

func WithCollection

func WithCollection(collection string, s func(*mgo.Collection) error) error

WithCollection 公共方法,使用 collection 对象 Usage:

error = mongo.WithCollection("name", func (conn *mgo.Collection) error {
    ... do something ...
})

Types

type Collection

type Collection interface {
	CollectionName() string
}

Collection mongodb collection interface

type DebugLogger

type DebugLogger struct {
}

DebugLogger for mongodb

func (DebugLogger) Output

func (d DebugLogger) Output(callDepth int, s string) error

Jump to

Keyboard shortcuts

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