I am trying to insert an array into a MongoDB instance using Go. I have the [] string
slice in Go and want to convert it into a BSON
array to pass it to the DB using the github.com/mongodb/mongo-go-driver
driver.
var result bson.Array
for _, data := range myData {
value := bson.VC.String(data)
result.Append(value)
}
This loops over each element of my input data and tries to append it to the BSON
array. However the line with the Append()
fails with panic: document is nil
. How should I do this conversion?