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

ReplaceOne result does not set UpsertedID and possibly MatchedCount is wrong

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • No Release
    • CRUD
    • None

    Description

      ReplaceOne perform as expected but UpdateResult is wrong:

       

      • MatchedCount always return 1 (possibly ok but logically should return all matched docs)
      • UpsertedID is nil

       

      Consider this sampel code:

      client, _ := mongo.NewClient("mongodb://localhost:27017")
      ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
      err := client.Connect(ctx)
      assert.Nil(t, err)
       
      c := client.Database("testing").Collection("c1")
       
      d1 := bson.M{"name": "pi", "value": 3.14159}
      d2 := bson.M{"name": "pi", "value": 3.14159}
      r, err := c.InsertMany(ctx, []interface{}{d1, d2})
      assert.Nil(t, err)
      assert.Len(t, r.InsertedIDs, 2)
       
      ror, err := c.ReplaceOne(ctx, nil, bson.M{"name": "pi", "value": -1})
      assert.Nil(t, err)
      // (1) MatchedCount expected to be 2
      fmt.Println(ror.MatchedCount)
      // (2) Expected to return the ID of the updated document but returns nil
      fmt.Println(ror.UpsertedID)
       
      c.Drop(ctx)
       

       

       

      Thanks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            asaf000 Asaf Shakarzy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: