Skip to content

Commit

Permalink
Add estimatedCount support (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
srt180 authored Jul 6, 2022
1 parent 7b27888 commit 48e2abe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type QueryI interface {
One(result interface{}) error
All(result interface{}) error
Count() (n int64, err error)
EstimatedCount() (n int64, err error)
Distinct(key string, result interface{}) error
Cursor() CursorI
Apply(change Change, result interface{}) error
Expand Down
5 changes: 5 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func (q *Query) Count() (n int64, err error) {
return q.collection.CountDocuments(q.ctx, q.filter, opt)
}

// EstimatedCount count the number of the collection by using the metadata
func (q *Query) EstimatedCount() (n int64, err error) {
return q.collection.EstimatedDocumentCount(q.ctx)
}

// Distinct gets the unique value of the specified field in the collection and return it in the form of slice
// result should be passed a pointer to slice
// The function will verify whether the static type of the elements in the result slice is consistent with the data type obtained in mongodb
Expand Down

0 comments on commit 48e2abe

Please sign in to comment.