From 3069e04546bb4ec4a2e206aa7fa995ec2f2ec64f Mon Sep 17 00:00:00 2001 From: jiangzhi Date: Sun, 15 Nov 2020 20:33:57 +0800 Subject: [PATCH] GODRIVER-1793 Avoid crash when opts is [nil] in InsertOne --- mongo/collection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongo/collection.go b/mongo/collection.go index c10522154a..42185f5548 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -329,7 +329,7 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{}, imOpts := make([]*options.InsertManyOptions, len(opts)) for i, opt := range opts { imo := options.InsertMany() - if opt.BypassDocumentValidation != nil && *opt.BypassDocumentValidation { + if opt != nil && opt.BypassDocumentValidation != nil && *opt.BypassDocumentValidation { imo = imo.SetBypassDocumentValidation(*opt.BypassDocumentValidation) } imOpts[i] = imo