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

MarshalBSONValue With Embedded struct

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • BSON
    • None
    • Mongodb: 4.0.5
      Go-Driver: 1.0.3
      Golang: 1.12

    Description

      Hi, i want to custom MarshalBSONValue like GODRIVER-980

       

      type StructA struct {
          ID `bson:"_id"` // <-- Embedded
          Foo string `bson: "Foo"`
      }
       
      type ID string 
       
      func (e ID) MarshalBSONValue() (bsontype.Type, []byte, error) {
          return bsontype.String, bsoncore.AppendString(nil, string(e)), nil
      }
      

       

       

      But my struct is embedded, it said

      cannot transform type *main.StructA to a BSON Document: WriteValueBytes can only write while positioned on a Element or Value but is positioned on a TopLevel
      

      What should i do?

      Attachments

        Activity

          People

            connie.yu@mongodb.com Run Tian Yu (Inactive)
            xlebenny Benny Leung
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: