Search code examples
gomongo-go

How to use the elements of a slice in bson.A using mongo-go-driver 0.2.0


How do I use a given slice to generate a bson.A? I need this to make dynamic queries.

I am upgrading from mongo-go-driver alpha to beta 0.2.0, and this has become a major change in my project since the API is different now.

https://godoc.org/github.com/mongodb/mongo-go-driver/bson

input := []string{"bar", "world"}
//expected output
bson.A{"bar", "world"}

Solution

  • So bson.A underlying type is []interface{},

    I could just use append to it like a slice