mgo$inc更新不工作

mgo$inc更新不工作,go,mgo,Go,Mgo,每次访问特定博客时,我都会尝试更新浏览次数 type Blog struct { ID bson.ObjectId `bson:"_id,omitempty"` Topic string TimeCreated string Views int Sections []Section } type Section struct { Name string Content string }

每次访问特定博客时,我都会尝试更新浏览次数

type Blog struct {
    ID          bson.ObjectId `bson:"_id,omitempty"`
    Topic       string
    TimeCreated string
    Views       int
    Sections    []Section
}
type Section struct {
    Name    string
    Content string
}
和控制者

func Blogs(w http.ResponseWriter, r *http.Request) {
    id := r.FormValue("id")
    if id != "" {
        blog := model.Blog{}
        colQuerier := bson.M{"_id": bson.ObjectIdHex(id)}

        e := mCollection.Find(colQuerier).One(&blog)
        if e != nil {
            console.PrintError(e)
            return
        }
        views := blog.Views
        fmt.Println(views)
        change := bson.M{"$inc": bson.M{"Views": 1}}

        e = mCollection.Update(colQuerier, change)
        if e != nil {
            console.PrintError(e)
        }

        jsonData, _ := json.Marshal(blog)
        fmt.Fprintf(w, string(jsonData))
     }
}
//控制台是一个内部包

代码获取内容但不增加视图

我找到了答案, 因此,即使模型有“视图”。在集合中,它是“视图”,所以它不断增加“视图”,因为golang正在寻找“视图”,所以从未出现过“视图”

所以工作代码是


change:=bson.M{“$inc”:bson.M{“视图”:1}

获取了无法识别的管道阶段名称$inc。。。你用的是哪个司机mongo?