Skip to content

Commit

Permalink
Set limit to -1 for Collection.FindOne
Browse files Browse the repository at this point in the history
GODRIVER-1112

Change-Id: I9f7b5b9c4a49bb54099b47422b605073f9790540
  • Loading branch information
Divjot Arora committed Jun 5, 2019
1 parent 5da0272 commit 2edf2a2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
Sort: opt.Sort,
}
}
// Unconditionally send a limit to make sure only one document is returned and the cursor is not kept open
// by the server.
findOpts = append(findOpts, options.Find().SetLimit(-1))

batchCursor, err := driver.Find(
ctx, cmd,
Expand Down

0 comments on commit 2edf2a2

Please sign in to comment.