【发布时间】:2017-01-23 16:52:33
【问题描述】:
我正在尝试使用 mgo 在 MongoDB 中插入一些数据,但结果不是我想要的。
我的结构
type Slow struct {
Endpoint string
Time string
}
我的插入语句
err := collection.Insert(&Slow{endpoint, e})
if err != nil {
panic(err)
}
我如何尝试打印它
var results []Slow
err := collection.Find(nil).All(&results)
if err != nil {
panic(err)
}
s, _ := json.MarshalIndent(results, " ", " ")
w.Write(s)
我的输出(编组 JSON)
[{
"Endpoint": "/api/endpoint1",
"Time": "0.8s"
},
{
"Endpoint": "/api/endpoint2",
"Time": "0.7s"
}]
我想要什么
{
"/api/endpoint1":"0.8s",
"/api/endpoint2":"0.7s"
}
//No brackets
谢谢。
【问题讨论】: