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

Upsert in findOneAndUpdate not work

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Major - P3 Major - P3
    • None
    • 1.7.4
    • None
    • Not Needed

    Description

      MogoDB version: 5.0.3

      Driver version: v1.7.4

      Code:
      type mongoCounter struct {
      Type string `bson:"type"`
      Sequence int `bson:"sequence"`
      }
      result := mongoCounter{}
      err = db.Collection("counters").FindOneAndUpdate(context.Background(), bson.M{
      "type": "non_existen_type",
      }, bson.M{
      "$inc": bson.M{
      "sequence": 1,
      },
      }, options.FindOneAndUpdate().SetUpsert(true)).Decode(&result)
      fmt.Println(err)
       

       

       

      Result:

       

      mongo: no documents in result

       

      Expected:

      The document should be created and err is nil.

      Attachments

        Activity

          People

            benji.rewis@mongodb.com Benji Rewis (Inactive)
            oxycoder@gmail.com Tung Nguyen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: