mongodb ( mgo )から取得したデータを処理しようとしています。
残念ながら、文字列のリストの正しい型をアサートできません。私が取り組んでいる機能は次のとおりです。
func generate_version_histogram(userStats []interface{}) map[string]int {
var histogram map[string]int
for _, _u := range userStats {
u := _u.(bson.M)
for _, version := range (u["v"]).([]string) {
if _, alreadyhere := histogram[version]; alreadyhere {
histogram[version] += 1
} else {
histogram[version] = 1
}
}
}
return histogram
}
残念ながら、次の実行時パニックが発生しています。
interface conversion: interface is []interface {}, not []string
なぜこれが起こっているのかについて何か考えはありますか?これらの文字列を取得するにはどうすればよいですか?