일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 김양재 목사
- node.js
- Artificial Intelligence
- 김양재
- R
- c++
- Statistics
- 데이터 과학
- 빅 데이타
- WebGL
- 우리들교회
- openCV
- 확률
- 빅데이터
- 몽고디비
- 빅 데이터
- Big Data
- 인공지능
- MongoDB
- 통계
- Deep learning
- No SQL
- 딥러닝
- probability
- data science
- nodeJS
- Machine Learning
- 빅데이타
- 주일설교
- 김양재 목사님
- Today
- Total
Scientific Computing & Data Science
[MongoDB] Update Modifiers / Part. 3 - $inc 본문
Written by cinema4d
Incrementing & Decrementing
The "$inc" modifier changes the value for an existing key which is type "number" or creates a new key of type "number" if not exist.
Suppose we are managing the scores of students, for example:
// define
var student1 = {"name" : "gchoi", "score" : 90};
var student2 = {"name" : "jmpark", "score" : 40};
// insert
db.student.insert(student1);
db.student.insert(student2);
Check the result:
> db.student.find() { "_id" : ObjectId("52dd2a8835f6aa029e32a28a"), "name" : "gchoi", "score" : 90 } { "_id" : ObjectId("52dd2a8935f6aa029e32a28b"), "name" : "jmpark", "score" : 40 }
The student "jmpark" studied very hard to increment his score by 60 points. As a result he earns 100 points.
The modifier "$inc" is used to increase the score of the student "jmpark" as:
db.student.update({"name" : "jmpark"}, {"$inc" : {"score" : 60}});
Result:
> db.student.find() { "_id" : ObjectId("52dd2a8835f6aa029e32a28a"), "name" : "gchoi", "score" : 90 } { "_id" : ObjectId("52dd2a8935f6aa029e32a28b"), "name" : "jmpark", "score" : 100 }
'Data Science > MongoDB' 카테고리의 다른 글
[MongoDB] Application / MongoDB - Node.js 연동하기 (2) | 2014.01.21 |
---|---|
[MongoDB] Application / Mongo Lab 사용하기 (1) | 2014.01.21 |
[MongoDB] Application / Execute MongoDB Server on Windows (0) | 2014.01.20 |
[MongoDB] Update Modifiers / Part. 2 - $set / $unset (0) | 2014.01.19 |
[MongoDB] Update Modifiers / Part.1 - $inc (0) | 2014.01.19 |