FindOne.Decode not decoding embedded struct fields

XMLWordPrintableJSON

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

      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:
              Emmanuel Eppinger (Inactive)
              Reporter:
              prakash
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: