title: Insert document into mongodb with one field having dynamic structure
body: <p>I'm trying to insert to MongoDB with Go where one field will have dynamic data. In my case, it will come from the other service through gRPC but I simplified example to this:</p>
  
  <pre><code>package main
  
  import (
      "context"
      "fmt"
      _struct "github.com/golang/protobuf/ptypes/struct"
      "go.mongodb.org/mongo-driver/bson/primitive"
      "go.mongodb.org/mongo-driver/mongo"
      "go.mongodb.org/mongo-driver/mongo/options"
      "log"
  )
  
  type siteItem struct {
      ID   primitive.ObjectID `bson:"_id,omitempty"`
      Name string             `bson:"name"`
  
      // Data string     `bson:"data"`
      Data *_struct.Value `bson:"data"`
  }
  
  func main() {
      client, _ := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
      client.Connect(context.TODO())
      collection := client.Database("site").Collection("sites")
  
      data := siteItem{
          Name: "Test name",
  
          // Data: "Test data",
          Data: &amp;_struct.Value{
              Kind: &amp;_struct.Value_StringValue{
                  StringValue: "String from struct",
              },
          },
      }
  
      res, err := collection.InsertOne(context.Background(), data)
      if err != nil {
          log.Fatal(err)
      }
  
      fmt.Println(res)
  }
  </code></pre>
  
  <p>And I get an error: <code>cannot transform type main.siteItem to a BSON Document: no encoder found for structpb.isValue_Kind</code></p>
  
  <p>If I use <code>string</code> instead of <code>*_struct.Value</code> - it works just fine. But in my case <code>Data:</code> might have any value that comes from JSON.</p>