From 9c8d40d3baff737c1b2e41d3e3370d2e9fef1baa Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Fri, 23 Jan 2026 16:36:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20MongoDB=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=93=8D=E4=BD=9C=E4=B8=AD=20$set=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=9A=84=20panic=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongo/mongo.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mongo/mongo.go b/mongo/mongo.go index c86cb62..c262864 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -498,7 +498,10 @@ func (m *MongoDB) Update(ctx context.Context, filter bson.M, update bson.M, coll } } } - setDoc := update["$set"].(bson.M) + setDoc := bson.M{} + if !g.IsEmpty(update["$set"]) { + setDoc = update["$set"].(bson.M) + } if !g.IsEmpty(user.UserName) { setDoc["updater"] = user.UserName }