mongo driver 的 countdocument方法

This commit is contained in:
Cold
2025-11-25 16:37:29 +08:00
committed by 张斌
parent 8665705f26
commit 62f545affd

View File

@@ -94,3 +94,10 @@ func Insert(ctx context.Context, documents []interface{}, collection string, opt
ids = r.InsertedIDs ids = r.InsertedIDs
return 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
}