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
	}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM