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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 1.1.2
    • BSON
    • None
    • go 1.13, linux

    Description

      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
      }

      ```

      Attachments

        Activity

          People

            Unassigned Unassigned
            evghenii.maslennikov@gmail.com Evghenii Maslennikov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: