Documentation ¶
Index ¶
- func BuildWhere(Filter []string) [][]interface{}
- func Close()
- func GetConfig() (string, string, uint64, int)
- func InitEngine(databaseName ...string) error
- type Mgo
- func (m *Mgo) Aggregate() (*mongo.Cursor, error)
- func (m *Mgo) Count(count *int64) *Mgo
- func (m *Mgo) Create(data interface{}) (*mongo.InsertOneResult, error)
- func (m *Mgo) Delete(update interface{}) (*mongo.DeleteResult, error)
- func (m *Mgo) DeleteMany(update interface{}) (*mongo.DeleteResult, error)
- func (m *Mgo) Distinct(name string) ([]interface{}, error)
- func (m *Mgo) Find() (*mongo.Cursor, error)
- func (m *Mgo) FindOne(v interface{}) error
- func (m *Mgo) GetCtx() context.Context
- func (m *Mgo) Limit(limit int64) *Mgo
- func (m *Mgo) SaveAll(data []interface{}) (*mongo.InsertManyResult, error)
- func (m *Mgo) SetDatabase(databaseName string) *Mgo
- func (m *Mgo) Skip(skip int64) *Mgo
- func (m *Mgo) Sort(sort map[string]interface{}) *Mgo
- func (m *Mgo) StartTrans(fn func(mongo.SessionContext) error)
- func (m *Mgo) Table(tableName string) *Mgo
- func (m *Mgo) Update(filter interface{}, update interface{}) (*mongo.UpdateResult, error)
- func (m *Mgo) UpdateById(id string, update interface{}) (*mongo.UpdateResult, error)
- func (m *Mgo) Where(filter interface{}) *Mgo
- type Pages
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitEngine ¶ added in v1.5.2
InitEngine 初始化 参考文档 https://docs.mongodb.com/drivers/go/
Types ¶
type Mgo ¶
type Mgo struct { Database *mongo.Database //数据库 Ctx context.Context Collection *mongo.Collection Cancel context.CancelFunc DataBaseName string TableName string Filter interface{} Pages Pages Timeout int Err error sync.Mutex }
Mgo
func NewMongoDB ¶ added in v1.5.2
Connect Default connection<默认连接> 参考文档 https://docs.mongodb.com/drivers/go/
func (*Mgo) Aggregate ¶
Aggregate Aggregate advanced queries<聚合高级查询> id, _ := primitive.ObjectIDFromHex("5e3b37e51c9d4400004117e6") matchStage := bson.D{{"$match", bson.D{{"podcast", id}}}} groupStage := bson.D{{"$group", bson.D{{"_id", "$podcast"}, {"total", bson.D{{"$sum", "$duration"}}}}}} mongo.Pipeline{matchStage, groupStage}
func (*Mgo) Create ¶
func (m *Mgo) Create(data interface{}) (*mongo.InsertOneResult, error)
Create Create data<创建数据>
func (*Mgo) Delete ¶
func (m *Mgo) Delete(update interface{}) (*mongo.DeleteResult, error)
Delete delete data<删除>
func (*Mgo) DeleteMany ¶
func (m *Mgo) DeleteMany(update interface{}) (*mongo.DeleteResult, error)
DeleteMany Delete multiple data<删除多个数据>
func (*Mgo) SaveAll ¶
func (m *Mgo) SaveAll(data []interface{}) (*mongo.InsertManyResult, error)
SaveAll save all data<创建多条数据>
func (*Mgo) SetDatabase ¶
SetDatabase Modify database switch<修改数据库切换>
func (*Mgo) StartTrans ¶
func (m *Mgo) StartTrans(fn func(mongo.SessionContext) error)
StartTrans 开启事务 sessionContext.StartTransaction() 开启事务 sessionContext.AbortTransaction(sessionContext) //终止事务 sessionContext.CommitTransaction(sessionContext) //提交事务
func (*Mgo) Update ¶
func (m *Mgo) Update(filter interface{}, update interface{}) (*mongo.UpdateResult, error)
Update Update data<修改数据>
func (*Mgo) UpdateById ¶
func (m *Mgo) UpdateById(id string, update interface{}) (*mongo.UpdateResult, error)
UpdateById Modify data according to id<根据id修改>
func (*Mgo) Where ¶
Where 条件 [][]string{{"test", "name"},{"test", "$lt","1"}}
map[string]interface{}{ "$or": []interface{}{map[string]interface{}{"author": "Nicolas222"}, map[string]interface{}{"author": "Nicolas333"}}, }
等于 {<key>:<value>} 小于 {<key>:{$lt:<value>}} 小于或等于 {<key>:{$lte:<value>}} 大于 {<key>:{$gt:<value>}} 大于或等于 {<key>:{$gte:<value>}} 不等于 {<key>:{$ne:<value>}}