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

bson can't marshal an interface

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.0.0
    • BSON
    • None

    Description

      I have an interface, let's say:

       
      type ITest interface {
          Hello()
      }
       
      Struct, which implements this:

      type STest struct {
          Greeting string
      }

      func (s *STest) Hello() {
          fmt.Println(s.Greeting)
      }
      And an array of ITest interfaces with a STest struct as first element:
       
      var iArr []ITest
      iArr = append(iArr, &STest{"heelloo"})
       
      When i'm trying to create an update document for UpdateOne method, i do the following:
       
      bson.D{{"$set", bson.D{{"somefield", iArr}}}}
       
      and getting an error:
       
      cannot transform type primitive.D to a BSON Document: no encoder found for models.ITest
       
      But for the separate element it works like a charm (no error, present in db):
       
      bson.D{{"$set", bson.D{{"somefield", iArr[0]}}}}
       
       
      So is it bug or something?

      PS: i'm using v1.0.0-rc1+prerelease version

      Attachments

        Activity

          People

            Unassigned Unassigned
            ollevche ollevche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: