Skip to content

Commit 1de35ec

Browse files
authored
Support options for Count and EstimatedCount (#323)
* suppert options for qmgo * suppert options for qmgo
1 parent 5d875cc commit 1de35ec

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ type QueryI interface {
6060
Limit(n int64) QueryI
6161
One(result interface{}) error
6262
All(result interface{}) error
63-
Count() (n int64, err error)
64-
EstimatedCount() (n int64, err error)
63+
Count(opts ...*options.CountOptions) (n int64, err error)
64+
EstimatedCount(opts ...*options.EstimatedDocumentCountOptions) (n int64, err error)
6565
Distinct(key string, result interface{}) error
6666
Cursor() CursorI
6767
Apply(change Change, result interface{}) error

query.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ func (q *Query) Sort(fields ...string) QueryI {
9090
return newQ
9191
}
9292

93-
// SetArrayFilter use for apply update array
94-
// For Example :
95-
// var res = QueryTestItem{}
96-
// change := Change{
97-
// Update: bson.M{"$set": bson.M{"instock.$[elem].qty": 100}},
98-
// ReturnNew: false,
99-
// }
100-
// cli.Find(context.Background(), bson.M{"name": "Lucas"}).
101-
// SetArrayFilters(&options.ArrayFilters{Filters: []interface{}{bson.M{"elem.warehouse": bson.M{"$in": []string{"C", "F"}}},}}).
102-
// Apply(change, &res)
93+
// SetArrayFilter use for apply update array
94+
// For Example :
95+
// var res = QueryTestItem{}
96+
// change := Change{
97+
// Update: bson.M{"$set": bson.M{"instock.$[elem].qty": 100}},
98+
// ReturnNew: false,
99+
// }
100+
// cli.Find(context.Background(), bson.M{"name": "Lucas"}).
101+
// SetArrayFilters(&options.ArrayFilters{Filters: []interface{}{bson.M{"elem.warehouse": bson.M{"$in": []string{"C", "F"}}},}}).
102+
// Apply(change, &res)
103103
func (q *Query) SetArrayFilters(filter *options.ArrayFilters) QueryI {
104104
newQ := q
105105
newQ.arrayFilters = filter
@@ -238,8 +238,8 @@ func (q *Query) All(result interface{}) error {
238238
}
239239

240240
// Count count the number of eligible entries
241-
func (q *Query) Count() (n int64, err error) {
242-
opt := options.Count()
241+
func (q *Query) Count(opts ...*options.CountOptions) (n int64, err error) {
242+
opt := options.MergeCountOptions(opts...)
243243

244244
if q.limit != nil {
245245
opt.SetLimit(*q.limit)
@@ -252,8 +252,10 @@ func (q *Query) Count() (n int64, err error) {
252252
}
253253

254254
// EstimatedCount count the number of the collection by using the metadata
255-
func (q *Query) EstimatedCount() (n int64, err error) {
256-
return q.collection.EstimatedDocumentCount(q.ctx)
255+
func (q *Query) EstimatedCount(opts ...*options.EstimatedDocumentCountOptions) (n int64, err error) {
256+
co := options.MergeEstimatedDocumentCountOptions(opts...)
257+
258+
return q.collection.EstimatedDocumentCount(q.ctx, co)
257259
}
258260

259261
// Distinct gets the unique value of the specified field in the collection and return it in the form of slice

0 commit comments

Comments
 (0)