golang mongodb upsert

前端之家收集整理的这篇文章主要介绍了golang mongodb upsert前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//UpsertPhoneInterface
func UpsertPhoneInterface(_query,update bson.M) (err error) {
query := func(c *mgo.Collection) error {
_,err = c. Upsert(_query,update)
return err
}
getCollection( "perfInterface",query)
return
}
q := bson.M{ "serial": serial}
p := bson.M{ "serial": serial,"timestamp": stamptime, "ip": ip,"jtype": "serial-ip"}

log. Info(q,p)
err = db. UpsertPhoneInterface(q,p)
if err != nil {
ret := map[ string] interface{}{ "code": "000404","msg": "fail to insert to mongodb"}
return c. JSON( 400,ret)
}
原文链接:https://www.f2er.com/go/188253.html

猜你在找的Go相关文章