From f31bf24ec2efadad0158d8a785f7d00a54b88ed3 Mon Sep 17 00:00:00 2001 From: hoteas Date: Tue, 30 Aug 2022 04:44:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0mongodb=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E7=AE=80=E5=8D=95=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dri/mongodb/mongodb.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dri/mongodb/mongodb.go b/dri/mongodb/mongodb.go index 437301f..24c1964 100644 --- a/dri/mongodb/mongodb.go +++ b/dri/mongodb/mongodb.go @@ -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