Mongo db modifiers

67 views

Published on

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

Published in: Technology, Spiritual
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
67
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mongo db modifiers

  1. 1. MongoDB Modifier’sModifiers
  2. 2. $inc> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 32}Increment the uName=anish age to 1> db.user.update({"_id" :ObjectId("513c6ef1cfce9090d3fd8b1d")},{"$inc" : {"age" :1}})> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 33}
  3. 3. $set> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 33}Set the uName=anish age to 31> db.user.update({"_id" :ObjectId("513c6ef1cfce9090d3fd8b1d")},{"$set" : {"age" : 31}})> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 31,}
  4. 4. $unset> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 33}Remove the age key> db.user.update({"_id" :ObjectId("513c6ef1cfce9090d3fd8b1d")},{"$unset" : {"age" : 31}})> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"date" : ISODate("2013-03-10T11:30:50.555Z"),"uName" : "anish"}
  5. 5. $PUSHAdd a array to the exisitng document> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"uName" : "anish","date" : ISODate("2013-03-10T11:30:50.555Z"),"age" : 33}PUSH the remark array in the documentdb.user.update({"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d")}, {$push : {"remarks" : {"name":"anish","rate":"good"}}})> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"date" : ISODate("2013-03-10T11:30:50.555Z"),"remarks" : [{"name" : "anish","rate" : "good"}],"uName" : "anish"}Add existing to the remarks array> db.user.update({"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d")}, {$push : {"remarks" : {"name":"nath","rate":"bad"> db.user.findOne(){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"date" : ISODate("2013-03-10T11:30:50.555Z"),"remarks" : [{"name" : "anish","rate" : "good"},{"name" : "nath","rate" : "bad"}],"uName" : "anish"}
  6. 6. Thanks for Watchingfeedbackappreciated…………………………

×