diff --git a/interface.go b/interface.go index 8910c53..e27bf6b 100644 --- a/interface.go +++ b/interface.go @@ -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 diff --git a/query.go b/query.go index ca1f5e1..abb25ac 100644 --- a/query.go +++ b/query.go @@ -29,13 +29,14 @@ 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 @@ -43,6 +44,12 @@ type Query struct { 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 { @@ -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 @@ -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