mongo driver 的 countdocument方法
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user