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

For nil options, InsertMany and InsertOne have different behaviors

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4.4
    • Component/s: None
    • Security Level: Public
    • Labels:
      None
    • Environment:
      mongoDB go driver v1.4.0
    • Backwards Compatibility:
      Minor Change

      Description

      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
         }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: