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
	}

  

 

posted @ 2020-04-02 14:17  bobojiang2016  阅读(1759)  评论(0编辑  收藏  举报