[GODRIVER-636] Add documentation on how to set a custom bsoncodec.Registry Created: 13/Nov/18  Updated: 27/Oct/23  Resolved: 07/Jan/19

Status: Closed
Project: Go Driver
Component/s: Documentation
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Tom Zierbock Assignee: Unassigned
Resolution: Gone away Votes: 1
Labels: beta
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-681 Cursors and SingleResult ignore clien... Closed

 Description   

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

{                         return reg                     }

),
                }
            }),
        },
    }
 
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)



 Comments   
Comment by Kristofer Brandow (Inactive) [ 07/Jan/19 ]

Hi tomzierbock,

Given the change made in mongodb/mongo-go-driver/pull/122, I don't think we need to document this anymore. If you disagree, please reply back and we'll reopen this ticket.

Thanks,

Kris

Generated at Thu Feb 08 08:34:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.