Your SlideShare is downloading. ×
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 updatedocumentusecases

63
views

Published on

Visit …

Visit
http://www.zariga.com
http://www.youtube.com/user/zarigatongy

Mongo db updatedocumentusecases


1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
63
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
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 updating DocumentUpdating Document Use Casedetailedzariga.com
  • 2. Updating Document <K,V>> db.user.find(){ "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"), "uName" : "nath", "date" :ISODate("2013-03-10T11:30:50.555Z") }Update the uName with “anish”Step 1 find userName with “nath”> var test=db.user.findOne({"uName":"nath"})Step 2> test.uName="anish"anishStep 3>db.user.update({"uName":"nath"},test)> db.user.findOne(){ "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish", "date" : ISODate("2013-03-10T11:30:50.555Z") }zariga.com
  • 3. Updating Document adding a new <k,V> to the document> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "nath","date" : ISODate("2013-03-10T11:30:50.555Z")}Add a age in the document i.e{"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 32}Step 1 : findByIdvar findById=db.user.findOne({"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d")})Step2 : add age to the document> findById.age=3232Step 3 Update the Document> db.user.update({"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d")},findById)> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 32}zariga.com
  • 4. Updating Document :Add a new Structure in the existing Document> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 32}Change the Document to the following{"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 32,"family" : {"motherName" : "Indu","wifeName" : "manisha","fatherName" : "Anil"}}zariga.com
  • 5. Updating Document :Add a new Structure in the existing DocumentStep 1 : findUserById>var findById=db.user.findOne({"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d")})Step 2: Add a family JSON entry>findById.family={"motherName":"Indu","wifeName":"manisha","fatherName":"Anil"}{ "motherName" : "Indu", "wifeName" : "manisha", "fatherName" : "Anil" }Step 3 : Update the docuemt :> db.user.update({"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d")},findById)Step 4 : Search the User DB> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 32,"family" : {"motherName" : "Indu","wifeName" : "manisha","fatherName" : "Anil"}}zariga.com
  • 6. Thanks for Watchingfeedbackappreciated…………………………zariga.com