Not sure if you ever found your answer, but I battled with this for an hour+ yesterday.
I'm not positive this will solve what you're asking. I assume you're trying to build a filter from your input. Ultimately I did not use a bson.A when I was trying to pass an array.
Situation: Trying to build a filter and one of the bson.D elements is an array.
I thought I needed to use bson.A.
My initial assumption:
return bson.D{
{"uuid", request.Uuid},
{"action", request.Action},
{"resource", bson.D{{"$in", bson.A{resourceStrings}}}},
}
where resourceStrings
is a slice of strings.
However this will ultimately build a filter that looks like
FILTER : [ {resource [{$in [[Orgs::Organizations::1 Orgs::Organizations::* Orgs::Organizations Orgs::*]]}]}]
*Note that the $in method is looking for an array of arrays here.
What we want is:
FILTER : [{uuid 80} {action UpdateOrganization} {resource [{$in [Orgs::Organizations::1 Orgs::Organizations::* Orgs::Organizations Orgs::*]}]}]
If we pass in a literal array of strings it will work...
return bson.D{
{"uuid", request.Uuid},
{"action", request.Action},
{"resource", bson.D{{"$in", bson.A{"Orgs::Organizations::1", "Orgs::Organizations::*", "Orgs::Organizations", "Orgs::*"}}}},
}
After some trial and error I found that bson.D will directly accept the array.
ultimately I solved the issue thus
return bson.D{
{"uuid", request.Uuid},
{"action", request.Action},
{"resource", bson.D{{"$in", resourceStrings}}},
}
Taking your example literally - if you're simply trying to marshal an array to a bson.A try:
bson.A{input}