首页 > 数据库技术 > 详细

MongoDB修改器的使用2

时间:2016-06-15 00:00:17      阅读:326      评论:0      收藏:0      [点我收藏+]

1."$inc"的使用

  主要用来增加数值,比如网站的访问量,点击量,流量等

1 db.games.insert({game:"pinball",user:"joe"})
2 db.games.find()
3 db.games.update({"game":"pinball","user":"joe"},{"$inc":{"score":50}})
4 db.games.update({"game":"pinball","user":"joe"},{"$inc":{"score":10000}})

运行结果分别为

1 /* 1 */
2 {
3     "_id" : ObjectId("575a37da8fd26400d774e00a"),
4     "game" : "pinball",
5     "user" : "joe",
6     "score" : 10150.0
7 }
db.games.update({"game":"pinball","user":"joe"},{"$inc":{"score":50}})

1 /* 1 */
2 {
3     "_id" : ObjectId("575a37da8fd26400d774e00a"),
4     "game" : "pinball",
5     "user" : "joe",
6     "score" : 10200.0
7 }

 

MongoDB修改器的使用2

原文:http://www.cnblogs.com/lwy19998273333/p/5573490.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!