增加mongodb驱动,简单版本

This commit is contained in:
hoteas 2022-08-30 04:44:37 +08:00
parent 30edb4d9fa
commit f31bf24ec2
1 changed files with 26 additions and 0 deletions

View File

@ -65,6 +65,32 @@ func (that *mongoDb) InsertMany(table string, data ...interface{}) Slice {
}
func (that *mongoDb) Update(table string, data Map, where Map) int64 {
collection := that.DataBase.Collection(table)
re, err := collection.UpdateMany(that.Ctx, where, data)
if err != nil {
that.LastErr = err
return 0
}
return re.ModifiedCount
}
func (that *mongoDb) Delete(table string, where Map) int64 {
collection := that.DataBase.Collection(table)
re, err := collection.DeleteMany(that.Ctx, where)
if err != nil {
that.LastErr = err
return 0
}
return re.DeletedCount
}
func (that *mongoDb) Get(table string, where Map) Map {
results := []Map{}
var cursor *mongo.Cursor