I have a map[string]interface{} that generated from a mongo query that is using the new mongo-go-driver
I want to process certain values in the map and replace the £ characters in the values belonging to the aggregate key
Here is the map:
result2 = map[aggregate:[map[£match:map[Source:Cities]] map[£sort:map[Order:1]]] collection:aggregate_stats db:stats]
Looping through the map:
for key, value := range result2 {
fmt.Println("key from result2:", key, " || ", "value from result 2:", value)
if key == "aggregate" {
fmt.Println("FOUND AGGREGATE || ", "value:", value, " || type: ", reflect.TypeOf(value))
}
if valueMSI, ok := value.([]interface{}); ok {
fmt.Println("Working", valueMSI)
fmt.Println(reflect.TypeOf(valueMSI))
}
}
Now, in the if statement checking for the aggregate key, the output of the first print statement gives the type as:
primitive.A
But it appears to be an []interface{} of maps when printed? [see result2]
Bearing that in mind, why isn't the second if statement evaluated?
Does this mean that primitive.A != array of interfaces?
In the documentation https://godoc.org/go.mongodb.org/mongo-driver/bson/primitive type A is defined as "An A represents a BSON array. This type can be used to represent a BSON array in a concise and readable manner. It should generally be used when serializing to BSON. For deserializing, the RawArray or Array types should be used."
How can I do this? I want to access the values for the aggregate key?