golang mongodb upsert
发布时间:2020-12-16 18:10:16 所属栏目:大数据 来源:网络整理
导读://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{
//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)
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |