Skip to content

Commit 94985f5

Browse files
Deprecate direct BSON unmarshaling support for op result types. (#902)
Co-authored-by: Benjamin Rewis <[email protected]>
1 parent fd104b9 commit 94985f5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

mongo/results.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type InsertManyResult struct {
4747
InsertedIDs []interface{}
4848
}
4949

50+
// TODO(GODRIVER-2367): Remove the BSON struct tags on DeleteResult.
51+
5052
// DeleteResult is the result type returned by DeleteOne and DeleteMany operations.
5153
type DeleteResult struct {
5254
DeletedCount int64 `bson:"n"` // The number of documents deleted.
@@ -91,7 +93,11 @@ type UpdateResult struct {
9193
}
9294

9395
// UnmarshalBSON implements the bson.Unmarshaler interface.
96+
//
97+
// Deprecated: Unmarshalling an UpdateResult directly from BSON is not supported and may produce
98+
// different results compared to running Update* operations directly.
9499
func (result *UpdateResult) UnmarshalBSON(b []byte) error {
100+
// TODO(GODRIVER-2367): Remove the ability to unmarshal BSON directly to an UpdateResult.
95101
elems, err := bson.Raw(b).Elements()
96102
if err != nil {
97103
return err

mongo/results_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
func TestResults(t *testing.T) {
1717
t.Run("delete result", func(t *testing.T) {
18+
// TODO(GODRIVER-2367): Do not test the ability to unmarshal BSON directly to a DeleteResult.
1819
t.Run("unmarshal into", func(t *testing.T) {
1920
doc := bson.D{
2021
{"n", int64(2)},
@@ -29,6 +30,7 @@ func TestResults(t *testing.T) {
2930
assert.Nil(t, err, "Unmarshal error: %v", err)
3031
assert.Equal(t, int64(2), result.DeletedCount, "expected DeletedCount 2, got %v", result.DeletedCount)
3132
})
33+
// TODO(GODRIVER-2367): Do not test the ability to marshal a DeleteResult to BSON.
3234
t.Run("marshal from", func(t *testing.T) {
3335
result := DeleteResult{DeletedCount: 1}
3436
buf, err := bson.Marshal(result)
@@ -53,6 +55,7 @@ func TestResults(t *testing.T) {
5355
})
5456
})
5557
t.Run("update result", func(t *testing.T) {
58+
// TODO(GODRIVER-2367): Do not test the ability to unmarshal BSON directly to an UpdateResult.
5659
t.Run("unmarshal into", func(t *testing.T) {
5760
doc := bson.D{
5861
{"n", 1},

0 commit comments

Comments
 (0)