Documentation ¶
Index ¶
- func CloseSession()
- func Connection() *mgo.Session
- func DeleteById(cName string, id string) (code int, err error)
- func FindAllByPage(cName string, query bson.M, sort string, fields string, page int, limit int, ...) (err error)
- func FindById(cName string, id string, model interface{}, fields string) (code int, err error)
- func FindOne(cName string, query bson.M, model interface{}, fields string) (code int, err error)
- func InitMongo() (err error)
- func TransList2BsonM(ls []string) (bm bson.M)
- func TransMap2BsonM(mp map[string]interface{}) bson.M
- func TransStruct2BsonM(obj interface{}) bson.M
- func UpdateBy(cName string, query bson.M, change bson.M) (code int, err error)
- func UpdateById(cName string, id string, change bson.M) (code int, err error)
- func WithCollection(collection string, s func(*mgo.Collection) error) error
- type Collection
- type DebugLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connection ¶
Connection return new mongodb connection. Usage:
conn := mongo.Connection() defer conn.Close() ... do something ...
func DeleteById ¶
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 ¶
FindById Finding a record by primary key ID Usage: m := &mongo.Moment{} // NOTICE: please use ref mongo.FindById("collection name", "id", m)
func TransStruct2BsonM ¶
TransStruct2BsonM translate structure to map
func UpdateById ¶
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
Click to show internal directories.
Click to hide internal directories.