MarshalBSONValue With Embedded struct

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Environment:
      Mongodb: 4.0.5
      Go-Driver: 1.0.3
      Golang: 1.12
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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?

            Assignee:
            Run Tian Yu (Inactive)
            Reporter:
            Benny Leung
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: