-
Type:
Bug
-
Resolution: Works as Designed
-
Priority:
Major - P3
-
None
-
Affects Version/s: No Release
-
Component/s: CRUD
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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.