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
网页URL:https://www.cdcxhl.com/article42/gseoec.html
成都网站建设公司_创新互联,为您提供软件开发、、做网站、企业网站制作、网站维护、商城网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联