-
Type: Improvement
-
Resolution: Gone away
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: Documentation
At the moment it is not obvious how to set a custom registry, such that it is used both when writing to mongo and reading with a cursor.
Bellow an example of what is I had to do to get this t work:
rb := bson.NewRegistryBuilder()
cod := &UUIDCodec{}
tUUID := reflect.TypeOf(uuid.UUID{})
rb.RegisterDecoder(reflect.PtrTo(tUUID), bsoncodec.ValueDecoderFunc(cod.DecodeValue))
rb.RegisterEncoder(reflect.PtrTo(tUUID), cod)
reg := rb.Build()
opt := &options.ClientOptions{
Registry: reg,
TopologyOptions: []topology.Option{
topology.WithServerOptions(func(opts ...topology.ServerOption) []topology.ServerOption {
return []topology.ServerOption{
topology.WithRegistry(func(r *bsoncodec.Registry) *bsoncodec.Registry
),
}
}),
},
}
Adding this or something similar as an example, or even pushing this code into the SetRegistry method of the mongo.Options would be helpful.
client, err := mongo.NewClientWithOptions(url, opt)
- related to
-
GODRIVER-681 Cursors and SingleResult ignore client custom registry
- Closed