Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1793

For nil options, InsertMany and InsertOne have different behaviors

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      mongoDB go driver v1.4.0
    • Minor Change

      To coll.InsertMany(ctx,document, nil), InsertMany will use default options.InsertMany()

      To coll.InsertOne(ctx, document, nil), InsertOne will panic because opts is [nil], and opt.BypassDocumentValidation will panic for access nil opt.

      func (coll *Collection) InsertOne(ctx context.Context, document interface{},
         opts ...*options.InsertOneOptions) (*InsertOneResult, error) {
      
         imOpts := make([]*options.InsertManyOptions, len(opts))
         for i, opt := range opts {
            imo := options.InsertMany()
            if opt.BypassDocumentValidation != nil && *opt.BypassDocumentValidation {
               imo = imo.SetBypassDocumentValidation(*opt.BypassDocumentValidation)
            }
            imOpts[i] = imo
         }

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            jiangz0222@gmail.com 智 姜
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: