Encoder and Decoder Codec for decimal.Decimal{} as primitive.Decimal128 on official mongo-go-driver
import (
...
"github.com/muktihari/decimalcodec"
)
func main() {
rb := bsoncodec.NewRegistryBuilder()
// you might want to include defaults encoder and decoder as well
bsoncodec.DefaultValueDecoders{}.RegisterDefaultDecoders(rb)
bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb)
decimalcodec.RegisterEncodeDecoder(rb)
registry := rb.Build()
client, err := mongo.Connect(context.Background(),
options.Client().
ApplyURI("mongodb://localhost:27017").
SetRegistry(registry),
)
...
}