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

BSON Marshaller ignores fields of an embedded structure of the schema

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.0.0
    • BSON
    • None
    • Ubuntu 18.04 amd64

    Description

      I declare schemas. For example:

      type Embedded struct {
        Name string `bson:"name"`
      }
       
      type Main struct {
        Embedded
        OtherField int64 `bson:"otherField"`
      }
      

      When I try to load an instance of Main structure from the database, e.g.:

      cursor, err := client.Database("my").Collection("myColl").Find(context.TODO(), bsonD{})
       
      if err != nil {
       return err
      }
       
      for cursor.Next(context.TODO()) {
        var m Main
        if err := cursor.Decode(&m); err != nil {
          return err
        }
       
        fmt.Printf("name=\"%s\"\n", m.Name) // outputs `name=""`
      }
      

      Attachments

        Activity

          People

            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            devoter Alexey Nosov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: