【发布时间】:2015-03-15 04:17:44
【问题描述】:
我有以下结构
type Result struct {
nid string
timestamp int64
hexhash string
addr string
}
我想保存到 mongodb 中:
我创造它
r := Result{hex_id, int64(msg.timestamp.Unix()), hexhash, msg.addr.String()}
并测试是否创建正确:
fmt.Println(r)
这给了我期望的结果:
{b8da3f19d1318af6879976c1eea66c78c48e1144 1421417252 65072917F19D7F4C4B54C9C66A3EB31F77012981 127.0.0.1:65290}
然后我将它保存到mongo中:
h.c.Insert(r)
但在 mongo 我只看到空记录:
db.data.find()
{ "_id" : ObjectId("54b91a268da6c829a412cd4d") }
上面代码中的h定义为
type Handler struct {
storage map[string]Message
new_msg chan Message
new_inp chan Input
c *mgo.Collection
}
和
h.c = session.DB(DATABASE).C(COLLECTION)
【问题讨论】: