zoukankan      html  css  js  c++  java
  • 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
    	}
    

      

    种树最好的时间是十年前,其次是现在。
  • 相关阅读:
    1211.分割平衡字符串
    1282.用户分组
    分模块配置
    Spring Bean相关配置
    Spring IOC是什么
    Spring简介
    小黄衫感想
    团队展示
    原型设计
    结对作业
  • 原文地址:https://www.cnblogs.com/bobojiang/p/12619559.html
Copyright © 2011-2022 走看看