我在使用 mgo 在 mongodb 中保存 golang 结构时遇到问题。
type AN_Track_Log struct {
Id bson.ObjectId `bson:"_id,omitempty"`
user_session_id_str string `bson:"user_session_id_str"`
googleanaly_pixel_id_str string `bson:"googleanaly_pixel_id_str"`
perfaud_pixel_id_str string `bson:"perfaud_pixel_id_str"`
site_id_str string `bson:"site_id_str"`
metric_str string `bson:"metric_str"`
value_str string `bson:"value_str"`
event_str string `bson:"event_str"`
location_id_str string `bson:"location_id_str"`
referer_str string `bson:"referer_str"`
track_origin_str string `bson:"track_origin_str"`
fingerprint_str string `bson:"fingerprint_str"`
...
}
p_track_log.Id = bson.NewObjectId()
err := p_mongodb_coll.Insert(&p_track_log)
问题是,当 Insert() 调用完成时,数据库中唯一保留的就是一个空文档
{u'_id': ObjectId('561809d20037873154000003')}
我检查结构字段确实已设置,并且不为空。
关于为什么会发生这种情况的任何想法。
感谢提示:) 谢谢
你需要export https://golang.org/ref/spec#Exported_identifiers字段名称以大写字母开头。
type AN_Track_Log struct {
Id bson.ObjectId `bson:"_id,omitempty"`
User_session_id_str string `bson:"user_session_id_str"`
Googleanaly_pixel_id_str string `bson:"googleanaly_pixel_id_str"`
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)