Your SlideShare is downloading. ×
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Mongo db문서의생성,갱신,삭제

828

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
828
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. MongoDB 3. , , twitter.com/jun0683
  • 2. • • • •
  • 3. 1. insert > db.foo.insert({"bar" : "baz"}) “_id”
  • 4. 1. X 16MB X (http://www.mongodb.org/display/DOCS/Import+Export+Tools)
  • 5. 1. BSON 4MB ( ,UTF-8, )
  • 6. 2. > db.users.remove() > db.mailing.list.remove({"opt-out" : true})
  • 7. 2. remove() find_one() db.drop_collection(“ ”)
  • 8. 3. update
  • 9. 3. { "_id" : ObjectId("4b2b9f67a1f631733d917a7a"), "name" : "joe", "friends" : 32, "enemies" : 2 } { "_id" : ObjectId("4b2b9f67a1f631733d917a7a"), "username" : "joe", "relationships" : { "friends" : 32, "enemies" : 2 } }
  • 10. { "_id" : ObjectId("4b2b9f67a1f631733d917a7a"), "name" : "joe", 3. "friends" : 32, "enemies" : 2 } { "_id" : ObjectId("4b2b9f67a1f631733d917a7a"), "username" : "joe", "relationships" : { "friends" : 32, "enemies" : 2 } } > var joe = db.users.findOne({"name" : "joe"}); > joe.relationships = {"friends" : joe.friends, "enemies" : joe.enemies}; { "friends" : 32, "enemies" : 2 } > joe.username = joe.name; "joe" > delete joe.friends; true > delete joe.enemies; true > delete joe.name; true > db.users.update({"name" : "joe"}, joe);
  • 11. 3. , , _id
  • 12. 3. $set , > db.users.findOne() { "_id" : ObjectId("4b253b067525f35f94b60a31"), "name" : "joe", "age" : 30, "sex" : "male", "location" : "Wisconsin" } > db.users.update({"_id" : ObjectId("4b253b067525f35f94b60a31")}, ... {"$set" : {"favorite book" : "war and peace"}}) > db.users.findOne() { "_id" : ObjectId("4b253b067525f35f94b60a31"), "name" : "joe", "age" : 30, "sex" : "male", "location" : "Wisconsin", "favorite book" : "war and peace" }
  • 13. 3. $set > db.users.update({"name" : “joe”}, ... {"$set" : "favorite book" : ["war and peace","foundation trilogy", "enders game"]})
  • 14. 3. $set > db.blog.posts.findOne() { "_id" : ObjectId("4b253b067525f35f94b60a31"), "title" : "A Blog Post", "content" : "...", "author" : { "name" : "joe", "email" : "joe@example.com" } } > db.blog.posts.update({"author.name" : "joe"}, {"$set" : {"author.name" : "joe schmoe"}}) > db.blog.posts.findOne() { "_id" : ObjectId("4b253b067525f35f94b60a31"), "title" : "A Blog Post", "content" : "...", "author" : { "name" : "joe schmoe", "email" : "joe@example.com" } }
  • 15. 3. $unset > db.users.findOne() { "_id" : ObjectId("4b253b067525f35f94b60a31"), "name" : "joe", "age" : 30, "sex" : "male", "location" : "Wisconsin" } > db.users.update({"name" : “joe”}, ... {"$unset" : {"location" : 1}}) > db.users.findOne() { "_id" : ObjectId("4b253b067525f35f94b60a31"), "name" : "joe", "age" : 30, "sex" : "male", "location" : "Wisconsin", }
  • 16. 3. $inc , , > db.games.insert({"game" : "pinball", "user" : "joe"}) > db.games.update({"game" : "pinball", "user" : "joe"}, ... {"$inc" : {"score" : 50}}) > db.games.find() { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "game" : "pinball", "name" : "joe", "score" : 50 }
  • 17. 3. $inc > db.games.find() { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "game" : "pinball", "name" : "joe", "score" : 50 } > db.games.update({"game" : "pinball", "user" : "joe"}, ... {"$inc" : {"score" : 10000}}) > db.games.find() { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "game" : "pinball", "name" : "joe", "score" : 10050 }
  • 18. 3. $push > db.blog.posts.findOne() { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "title" : "A blog post", "content" : "..." } > db.blog.posts.update({"title" : "A blog post"}, {$push : {"comments" : ... {"name" : "joe", "email" : "joe@example.com", "content" : "nice post."}}}) > db.blog.posts.findOne() { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "title" : "A blog post", "content" : "...", "comments" : [ { "name" : "joe", "email" : "joe@example.com", "content" : "nice post." }] }
  • 19. 3. $ne > db.papers.update({"authors cited" : {"$ne" : "Richie"}}, ... {$push : {"authors cited" : "Richie"}})
  • 20. 3. $addToSet > db.users.findOne({"_id" : ObjectId("4b2d75476cc613d5ee930164")}) { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "username" : "joe", "emails" : [ "joe@example.com", "joe@gmail.com", "joe@yahoo.com", ] } > db.users.update({"_id" : ObjectId("4b2d75476cc613d5ee930164")}, ... {"$addToSet" : {"emails" : "joe@gmail.com"}}) > db.users.findOne({"_id" : ObjectId("4b2d75476cc613d5ee930164")}) { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "username" : "joe", "emails" : [ "joe@example.com", "joe@gmail.com", "joe@yahoo.com", ] }
  • 21. 3. $addToSet > db.users.findOne({"_id" : ObjectId("4b2d75476cc613d5ee930164")}) { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "username" : "joe", "emails" : [ "joe@example.com", "joe@gmail.com", "joe@yahoo.com", ] } > db.users.update({"_id" : ObjectId("4b2d75476cc613d5ee930164")}, ... {"$addToSet" : {"emails" : "joe@hotmail.com"}}) > db.users.findOne({"_id" : ObjectId("4b2d75476cc613d5ee930164")}) { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "username" : "joe", "emails" : [ "joe@example.com", "joe@gmail.com", "joe@yahoo.com", "joe@hotmail.com" ] }
  • 22. 3. $each > db.users.update({"_id" : ObjectId("4b2d75476cc613d5ee930164")}, {"$addToSet" : ... {"emails" : {"$each" : ["joe@php.net", "joe@example.com", "joe@python.org"]}}}) > db.users.findOne({"_id" : ObjectId("4b2d75476cc613d5ee930164")}) { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "username" : "joe", "emails" : [ "joe@example.com", "joe@gmail.com", "joe@yahoo.com", "joe@hotmail.com" "joe@php.net" "joe@python.org" ] }
  • 23. 3. $pop {$pop : {key : 1}} {$pop : {key : -1}}
  • 24. 3. $pull > db.lists.insert({"todo" : ["dishes", "laundry", "dry cleaning"]}) > db.lists.update({}, {"$pull" : {"todo" : "laundry"}}) > db.lists.find() { "_id" : ObjectId("4b2d75476cc613d5ee930164"), "todo" : [ "dishes", "laundry", "dry cleaning" ] }
  • 25. 3. ( 0 ) “$” ( ) > db.blog.posts.findOne() { "_id" : ObjectId("4b329a216cc613d5ee930192"), "content" : "...", "comments" : [ {"comment" : "good post", "author" : "John", "votes" : 0}, {"comment" : "i thought it was too short", "author" : "Claire", "votes" : 3}, {"comment" : "free watches", "author" : "Alice", "votes" : -1} ] } > db.blog.update({"post" : post_id}, ... {"$inc" : {"comments.0.votes" : 1}}) > db.blog.update({"comments.author" : "John"}, ... {"$set" : {"comments.$.author" : "Jim"}})
  • 26. 3. 10 update $inc 7.33 $push 67.58
  • 27. 3. , blog = db.analytics.findOne({url : "/blog"}) if (blog) { blog.pageviews++; db.analytics.save(blog); } else { db.analytics.save({url : "/blog", pageviews : 1}) } db.analytics.update({"url" : "/blog"}, {"$inc" : {"visits" : 1}}, true) [ ], [ ], [ ]
  • 28. 3. save , > var x = db.foo.findOne() > x.num = 42 42 > db.foo.save(x) db.foo.update({"_id" : x._id}, x)
  • 29. 3. save , > db.users.update({birthday : "07/23/2011"}, ... {$set : {gift : "Happy Birthday!"}}, false, true) [ ], [ ], [ ],[ ]
  • 30. 3. (findAndModify) > ps = db.processes.find({"status" : "READY").sort({"priority" : -1}).limit(1).next() > db.processes.update({"_id" : ps._id}, {"$set" : {"status" : "RUNNING"}}) > do_something(ps); > db.processes.update({"_id" : ps._id}, {"$set" : {"status" : "DONE"}}) > ps = db.runCommand({"findAndModify" : "processes", ... "query" : {"status" : "READY"}, ... "sort" : {"priority" : -1}, ... "update" : {"$set" : {"status" : "RUNNING"}}).value > do_something(ps) > db.process.update({"_id" : ps._id}, {"$set" : {"status" : "DONE"}})
  • 31. 3. (findAndModify) update , remove , ,
  • 32. 4. insert,remove,update , , . ,
  • 33. 4. getLastError DB
  • 34. 4. _id DB
  • 35. 5. MongoDB DB , ,

×