From 62f545affd814cfc219874685503b0fdc1172f27 Mon Sep 17 00:00:00 2001 From: Cold <16419454+cold502@user.noreply.gitee.com> Date: Tue, 25 Nov 2025 16:37:29 +0800 Subject: [PATCH] =?UTF-8?q?mongo=20driver=20=20=E7=9A=84=20countdocument?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongo/mongo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mongo/mongo.go b/mongo/mongo.go index aadc838..f0a8eb2 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -94,3 +94,10 @@ func Insert(ctx context.Context, documents []interface{}, collection string, opt ids = r.InsertedIDs return } + +// Count 查询总数 +func Count(ctx context.Context, filter bson.M, collection string) (count int64, err error) { + // 调用驱动的 CountDocuments,在数据库端执行的 + count, err = db.Collection(collection).CountDocuments(ctx, filter) + return +} \ No newline at end of file