Mongo db readingdocumentusecases

75 views

Published on

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

Published in: Education, Technology, Business
  • Be the first to comment

  • Be the first to like this

Mongo db readingdocumentusecases

  1. 1. MongoDB Reading/findingDocumentReading/finding Document Use Casedetailed
  2. 2. Reading/finding in DocumentSyntaxdb.collection.find( <query>,<projection> )<query> argument corresponds tothe WHERE statement, and<projection> argument correspondsto the list of fields to select from theresult set.
  3. 3. findOne()Find the first record in the document> 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"}
  4. 4. findOne() : specify which key to return• Find the first record in the document and return only “_id”> db.user.findOne({},{"_id":1}){ "_id" : ObjectId("513c6ef1cfce9090d3fd8b1d") }• Find the first record in the document and return only“_id” and date> db.user.findOne({},{"_id":1,"date":1}){"_id" : ObjectId("513c6ef1cfce9090d3fd8b1d"),"date" : ISODate("2013-03-10T11:30:50.555Z")}• Find the first record in the document and return all thedata except the “_id” field> db.user.findOne({},{"_id":0}){"date" : ISODate("2013-03-10T11:30:50.555Z"),"remarks" : [{"name" : "anish","rate" : "good"},{"name" : "nath","rate" : "bad"}],"uName" : "anish"}
  5. 5. finding in Subdocument>db.user.find({"remarks.name":"anish" }){ "_id" :ObjectId("513c6ef1cfce9090d3fd8b1d"),"date" : ISODate("2013-03-10T11:30:50.555Z"), "remarks" : [ {"name" : "anish", "rate" : "good" }, {"name" : "nath", "rate" : "bad" } ],"uName" : "anish" }
  6. 6. findOne()/find()• Summary on <K,boolean>specify <“k”,0> or <“K”,1>to show/hide data to bereturned from thecollection
  7. 7. Thanks for Watchingfeedbackappreciated…………………………

×