golang 中mgo update报错: The dollar ($) prefixed field '$inc' in '$inc' is not valid for storage.
_, err := c.Find(bson.M{"index": index}).Apply(mgo.Change{ Upsert: true, ReturnNew: false, Update: bson.M{"create_time": time.Now(), "update_time": time.Now(), "operation": 0, "$inc": bson.M{"req_cnt": 1}}, }, nil) if err != nil { return err }
由于"$inc"和前面的update冲突,报错误:The dollar ($) prefixed field '$inc' in '$inc' is not valid for storage.
因此改为:
_, err := c.Find(bson.M{"index": index}).Apply(mgo.Change{ Upsert: true, ReturnNew: false, Update: bson.M{"$set": bson.M{"create_time": time.Now(), "update_time": time.Now(), "operation": 0}, "$inc": bson.M{"req_cnt": 1}}, }, nil) if err != nil { return err }
种树最好的时间是十年前,其次是现在。