mongo driver 的 countdocument方法

This commit is contained in:
Cold
2026-03-12 08:50:01 +08:00
committed by admin
parent 8665705f26
commit 62f545affd
+7
View File
@@ -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
}