Upsert in findOneAndUpdate not work

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.7.4
    • Component/s: None
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      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.

        1. returndocumentexample.go
          0.8 kB
          Benji Rewis

            Assignee:
            Benji Rewis (Inactive)
            Reporter:
            Tung Nguyen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: