Skip to content

Commit 48e2abe

Browse files
authored
Add estimatedCount support (#243)
1 parent 7b27888 commit 48e2abe

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type QueryI interface {
5757
One(result interface{}) error
5858
All(result interface{}) error
5959
Count() (n int64, err error)
60+
EstimatedCount() (n int64, err error)
6061
Distinct(key string, result interface{}) error
6162
Cursor() CursorI
6263
Apply(change Change, result interface{}) error

query.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func (q *Query) Count() (n int64, err error) {
221221
return q.collection.CountDocuments(q.ctx, q.filter, opt)
222222
}
223223

224+
// EstimatedCount count the number of the collection by using the metadata
225+
func (q *Query) EstimatedCount() (n int64, err error) {
226+
return q.collection.EstimatedDocumentCount(q.ctx)
227+
}
228+
224229
// Distinct gets the unique value of the specified field in the collection and return it in the form of slice
225230
// result should be passed a pointer to slice
226231
// The function will verify whether the static type of the elements in the result slice is consistent with the data type obtained in mongodb

0 commit comments

Comments
 (0)