일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 데이터 과학
- R
- 인공지능
- 김양재 목사님
- 우리들교회
- 빅 데이타
- c++
- 몽고디비
- data science
- Deep learning
- 빅데이터
- Big Data
- 주일설교
- No SQL
- openCV
- 확률
- 딥러닝
- Artificial Intelligence
- probability
- 통계
- 김양재 목사
- MongoDB
- node.js
- nodeJS
- 빅데이타
- 김양재
- Machine Learning
- 빅 데이터
- Statistics
- WebGL
- 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 |