diff --git a/docs/migration-2.0.md b/docs/migration-2.0.md index 3b0ad3b7fa..c0c6f3a20b 100644 --- a/docs/migration-2.0.md +++ b/docs/migration-2.0.md @@ -1183,8 +1183,20 @@ A new `RawArray` type has been added to the `bson` package as a primitive type t ### ValueMarshaler -The `MarshalBSONValue` method of the `ValueMarshaler` interface is only required to return a byte type value representing the BSON type to avoid importing the `bsontype` package. +The `MarshalBSONValue` method of the [ValueMarshaler](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueMarshaler) interface now returns a `byte` value representing the [BSON type](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#Type). That allows external packages to implement the `ValueMarshaler` interface without having to import the `bson` package. Convert a returned `byte` value to [bson.Type](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#Type) to compare with the BSON type constants. For example: + +```go +btype, _, _ := m.MarshalBSONValue() +fmt.Println("type of data: %s: ", bson.Type(btype)) +fmt.Println("type of data is an array: %v", bson.Type(btype) == bson.TypeArray) +``` ### ValueUnmarshaler -The `UnmarshalBSONValue` method of the `ValueUnmarshaler` interface is only required to take a byte type argument representing the BSON type to avoid importing the Go driver package. +The `UnmarshalBSONValue` method of the [ValueUnmarshaler](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler) interface now accepts a `byte` value representing the [BSON type](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#Type) for the first argument. That allows packages to implement `ValueUnmarshaler` without having to import the `bson` package. For example: + +```go +if err := m.UnmarshalBSONValue(bson.TypeEmbeddedDocument, bytes); err != nil { + log.Fatalf("failed to decode embedded document: %v", err) +} +```