Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-681

Cursors and SingleResult ignore client custom registry

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.2.0
    • Affects Version/s: 0.1.0
    • Component/s: Core API
    • Labels:
      None
    • Environment:
      golang 1.11.2, Windows 10

      Case:
      I have developed custom codec for Google protobuf wrappers (wrappers.BoolValue, etc.).
      See https://godoc.org/github.com/golang/protobuf/ptypes/wrappers for details.

      My code is:
      type ProtoWrappersValueCodec struct {
      }

      func (e *ProtoWrappersValueCodec) EncodeValue(ectx bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

      { ... some code }

      func (e *ProtoWrappersValueCodec) DecodeValue(ectx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { ... some code }

       

      I provide custom registry when create new client:
      rb := bson.NewRegistryBuilder()
      cod := &ProtoWrappersValueCodec{}
      rb.RegisterCodec(reflect.TypeOf(wrappers.BoolValue{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.BytesValue{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.DoubleValue{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.FloatValue{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.Int32Value{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.Int64Value{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.StringValue{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.UInt32Value{}), cod).
      RegisterCodec(reflect.TypeOf(wrappers.UInt64Value{}), cod)

      client, err := mongo.NewClientWithOptions("mongodb://localhost:27017",
      &options.ClientOptions

      { Registry: rb.Build(), }

      )

      So InsertOne command works great. BSON Encoder calls custom encoders.
      But FindOne ignores custom decoders.
      I debug driver and see:
      Result cursor registry is set by default registry.
      Looks like it is set by server's registry.
      Looks like server's registry is default registry.
      I don't know why but custom registry I provided to the client is ignored.

      Please let me know if you need more details.
      Thanks!

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            amsokol Aleksandr Sokolovskii
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: