From 2edf2a22890faf8bc9fc0f64e745e12428fc6cbf Mon Sep 17 00:00:00 2001 From: Divjot Arora Date: Wed, 5 Jun 2019 12:47:28 -0400 Subject: [PATCH] Set limit to -1 for Collection.FindOne GODRIVER-1112 Change-Id: I9f7b5b9c4a49bb54099b47422b605073f9790540 --- mongo/collection.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mongo/collection.go b/mongo/collection.go index 0e5bd2220b..e688904394 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -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,