重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

golang之mgo自增id

import (
  "fmt"
  "gopkg.in/mgo.v2"
  "gopkg.in/mgo.v2/bson"
  "../../funcs"
)

// id从1开始递增
func GenId(db *mgo.Database) (int64, error) {
  IDInt64 := struct {
     Value int64 `bson:"max_id"`
  }{Value: 1}
  _, err := db.C("gen_id").Find(bson.M{}).Apply(mgo.Change{Update: bson.M{"$inc": IDInt64}, Upsert: true, ReturnNew: true}, &IDInt64)
  return IDInt64.Value, err
}


网页题目:golang之mgo自增id
分享地址:http://cqcxhl.com/article/gseoec.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP