我在创建应用程序的过程中,我的后端处于lang并且数据库是mongoDB。我的问题是,我有我的结构映射声明如下需要帮助,以使用golang在我的mongodb数据库中存储类型接口的地图
Data struct {
data map[interface{}]interface{}
}
像
c.Insert(&data)
在增加值,这就像
var data Data
data["us"]="country"
data[2]="number"
data["mother"]="son"
余米将其插入后,当我插入此即时通讯失去我的密钥,只能看到值...
{
"_id" : Object Id("57e8d9048c1c6f751ccfaf50"),
"data" : {
"<interface {} Value>" : "country",
"<interface {} Value>" : "number",
"<interface {} Value>" : "son"
},
}
我可以通过任何方式使用接口,并在我的mongoDB中获得键和值。谢谢....
你在地图上的键是'string'吧?使用'map [string] interface {}'。或者,如果你确定数据类型(即你的值总是字符串,只需使用'map [string] string') – KBN