일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 빅 데이타
- Machine Learning
- node.js
- WebGL
- data science
- 김양재 목사
- 빅데이타
- Deep learning
- Artificial Intelligence
- 빅 데이터
- Statistics
- 빅데이터
- 김양재
- 딥러닝
- c++
- 통계
- 김양재 목사님
- MongoDB
- No SQL
- 우리들교회
- 주일설교
- nodeJS
- Big Data
- R
- 데이터 과학
- 인공지능
- openCV
- 몽고디비
- probability
- 확률
- Today
- Total
Scientific Computing & Data Science
[MongoDB] Update Modifiers / Part. 2 - $set / $unset 본문
[MongoDB] Update Modifiers / Part. 2 - $set / $unset
cinema4dr12 2014. 1. 19. 19:25Written by cinema4d
Update items using "$set" modifier :
"$set" modifier adds item(s) if the relevant key exists or creates the key when absent.
Type the following for data preparation:
// drop the current database
db.dropDatabase()
// define webpage1
var user1 = {"username" : "gchoi", "age" : 37, "sex" : "male"}
// insert items into DB
db.users.insert(user1)
db.users.find()
Result:
> db.users.find() { "_id" : ObjectId("52dba60d0ea42add16dec853"), "username" : "gchoi", "age" : 37, "sex" : "male" }
Type the following to create "favorite food" key:
// update(create "favorite food" key)
db.users.update({"username" : "gchoi"}, {"$set" : {"favorite food" : "김치볶음밥"}})
db.users.find()
Result:
> db.users.find() { "_id" : ObjectId("52dba60d0ea42add16dec853"), "age" : 37, "favorite food" : "김치볶음밥", "sex" : "male", "username" : "gchoi" }
Set "favorite food" as an array type:
db.users.update({"username" : "gchoi"}, {"$set" : {"favorite food" : ["돼지갈비", "삼겹살", "된장찌개"]}})
Result:
> db.users.find() { "_id" : ObjectId("52dbdd7aa1c05d0be00a4b63"), "age" : 37, "favorite food" : [ "돼지갈비", "삼겹살", "된장찌개" ], "sex" : "male", "username" : "gchoi" }
Now we use "$unset" to remove the key "favorite food" to return to the beginning as we type the following:
// remove "favorite food"
db.users.update({"username" : "gchoi"}, {"$unset" : {"favorite food" : 1}})
Result:
> db.users.find() { "_id" : ObjectId("52dbdd7aa1c05d0be00a4b63"), "age" : 37, "sex" : "male", "username" : "gchoi" }
'Data Science > MongoDB' 카테고리의 다른 글
[MongoDB] Update Modifiers / Part. 3 - $inc (0) | 2014.01.20 |
---|---|
[MongoDB] Application / Execute MongoDB Server on Windows (0) | 2014.01.20 |
[MongoDB] Update Modifiers / Part.1 - $inc (0) | 2014.01.19 |
[MongoDB] Updating Documents by Document Replacement (0) | 2014.01.19 |
[MongoDB] Basic / Life Cycle for MongoDB (0) | 2014.01.19 |