Support inline fields as pointer to struct/map (not just struct/map)

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.1.2
    • Component/s: BSON
    • None
    • Environment:
      go 1.13, linux
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Can't marshal/unmarshal inline structs that are under the pointer

      Example:
      ```golang

      package foobar

      import (
      "context"
      "go.mongodb.org/mongo-driver/mongo"
      "go.mongodb.org/mongo-driver/mongo/options"
      "log"
      "testing"
      "time"
      )

      type MContainer struct

      { M int `bson:"m,omitempty"` }

      type FoobarWithPointer struct

      { *MContainer `bson:",inline"` A int }

      type FoobarPointerless struct

      { MContainer `bson:",inline"` A int }

      func TestSandbox(t *testing.T) {
      ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
      client, _ := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))

      collection := client.Database("testing").Collection("numbers")
      _, err := collection.InsertOne(ctx, &FoobarPointerless{A: 1, MContainer: MContainer{M: 10}})
      log.Printf("pointerless: err = %s", err) // nil

      _, err = collection.InsertOne(ctx, &FoobarWithPointer{A: 1, MContainer: &MContainer{M: 10}})
      log.Printf("with pointer: err = %s", err) // cannot transform type *foobar.FoobarWithPointer to a BSON Document: (struct foobar.FoobarWithPointer) inline fields must be either a struct or a map
      }

      ```

            Assignee:
            Unassigned
            Reporter:
            Evghenii Maslennikov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: