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

FindOne.Decode not decoding embedded struct fields

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux-ubuntu

      I have this following structure in my collection

       

       

      {
       "userID": "1234",
       "name": "Prakash",
       "email": "prakash@example.com",
       "street1": "some street 1",
       "street2" : "some street 2",
       "city" : "some city",
       "state": "some state",
       "country": "some country"          
      }

      I am using the following struct (Address struct embedded)

      type User struct {
         UserID string `bson:"userID"`
         Name string `bson:"name"`
         Email string `bson:email"`
         Address
      }
      
      type Address struct {
         Street1 string `bson:"street1"`
         Street2 string `bson:"street2"`
         City string `bson:"city"`
         State string `bson:"state"`
         Country string `bson:"country"`
      }

       

       

      So, When I do

       

      user := &User{}
      collection.FindOne(ctx, bson.M{"userID": "1234"}).Decode(user)
      

      I am getting the userID, Name and Email field but the address fields are blank.

       

       

      And when I am using this user struct, everything is working fine and

      I am getting all data from MongoDB as required.

       

      type User struct {
          UserID string `bson:"userID"`
          Name string `bson:"name"`
          Email string `bson:email"`
          Street1 string `bson:"street1"`
          Street2 string `bson:"street2"`
          City string `bson:"city"`
          State string `bson:"state"`
          Country string `bson:"country"`
      }

       

       

            Assignee:
            manny.eppinger@mongodb.com Emmanuel Eppinger (Inactive)
            Reporter:
            prakashpandey prakash
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: