Skip to content

Commit

Permalink
add set noCursorTimeout (#251)
Browse files Browse the repository at this point in the history
Co-authored-by: Koston Zhuang <[email protected]>
  • Loading branch information
PPG007 and Koston Zhuang authored Jul 6, 2022
1 parent 0717261 commit 7b27888
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type QueryI interface {
Select(selector interface{}) QueryI
Skip(n int64) QueryI
BatchSize(n int64) QueryI
NoCursorTimeout(n bool) QueryI
Limit(n int64) QueryI
One(result interface{}) error
All(result interface{}) error
Expand Down
27 changes: 20 additions & 7 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,27 @@ import (

// Query struct definition
type Query struct {
filter interface{}
sort interface{}
project interface{}
hint interface{}
limit *int64
skip *int64
batchSize *int64
filter interface{}
sort interface{}
project interface{}
hint interface{}
limit *int64
skip *int64
batchSize *int64
noCursorTimeout *bool

ctx context.Context
collection *mongo.Collection
opts []qOpts.FindOptions
registry *bsoncodec.Registry
}

func (q *Query) NoCursorTimeout(n bool) QueryI {
newQ := q
newQ.noCursorTimeout = &n
return newQ
}

// BatchSize sets the value for the BatchSize field.
// Means the maximum number of documents to be included in each batch returned by the server.
func (q *Query) BatchSize(n int64) QueryI {
Expand Down Expand Up @@ -174,6 +181,9 @@ func (q *Query) All(result interface{}) error {
if q.batchSize != nil {
opt.SetBatchSize(int32(*q.batchSize))
}
if q.noCursorTimeout != nil {
opt.SetNoCursorTimeout(*q.noCursorTimeout)
}

var err error
var cursor *mongo.Cursor
Expand Down Expand Up @@ -273,6 +283,9 @@ func (q *Query) Cursor() CursorI {
if q.batchSize != nil {
opt.SetBatchSize(int32(*q.batchSize))
}
if q.noCursorTimeout != nil {
opt.SetNoCursorTimeout(*q.noCursorTimeout)
}

var err error
var cur *mongo.Cursor
Expand Down

0 comments on commit 7b27888

Please sign in to comment.