• Save
MongoDB- Crud Operation
Upcoming SlideShare
Loading in...5
×
 

MongoDB- Crud Operation

on

  • 545 views

 

Statistics

Views

Total Views
545
Views on SlideShare
505
Embed Views
40

Actions

Likes
3
Downloads
0
Comments
0

4 Embeds 40

http://www.edureka.co 17
http://www.edureka.in 13
http://www.slideee.com 8
https://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

MongoDB- Crud Operation MongoDB- Crud Operation Presentation Transcript

  • www.edureka.in/mongodbSlide 1 ®
  • www.edureka.in/mongodbSlide 2  Module 1  Introduction and Overview  No SQL  Module 2  CRUD Operations  CRUD Concerns  Module 3  Schema Design and Data Modeling  Comparison with Relational Systems  Module 4  Administration  Backup and Recovery  Module 5  Scalability and Availability  Replication and Sharding  Module 6  Indexing and Aggregation Frame work  Performance Tuning  Module 7  Application Engineering and Mongo DB Tools  Interface with Other Language  Module 8  Project, Additional Concepts and Cases Studies MongoDB Course Topics
  • www.edureka.in/mongodbSlide 3 MongoDB Course Module 02 : CRUD Operations
  • www.edureka.in/mongodbSlide 4 Topics of the Day Module 1 – Revision MongoDB Development Overview MongoDB Production Overview MongoDB CRUD Introduction MongoDB CRUD Concepts MongoDB CRUD Syntax & Queries
  • www.edureka.in/mongodbSlide 5 Annie’s Question- Related to Module1 What are typical uses for MongoDB?
  • www.edureka.in/mongodbSlide 6 Annie’s Answer Content management systems, Mobile applications, Gaming, E-commerce, Analytics, Archiving, Logging, Data Hub.
  • www.edureka.in/mongodbSlide 7 Annie’s Question Where you should not use MongoDB?
  • www.edureka.in/mongodbSlide 8 Annie’s Answer For those systems which require SQL, joins, and multi-object transactions.
  • www.edureka.in/mongodbSlide 9 Annie’s Question Does MongoDB handle caching?
  • www.edureka.in/mongodbSlide 10 Annie’s Answer Yes. MongoDB keeps all of the most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.
  • www.edureka.in/mongodbSlide 11 Annie’s Question What is the difference in mongo and mongos?
  • www.edureka.in/mongodbSlide 12 Annie’s Answer Mongo  For simple shell access Mongos  For Sharded Cluster
  • www.edureka.in/mongodbSlide 13 mongod (Mongo Database) mongos mongos mongos app dirver app dirver app dirverapp dirver Query Sender MongoDB Development Environment
  • www.edureka.in/mongodbSlide 14 app server app server app serverapp server Mongos Mongos Mongos Config 1 Config 2 Config 3 mongod mongod mongod Sahrd1 mongod mongod mongod Sahrd2 mongod mongod mongod Sahrd3 mongod mongod mongod Sahrd4 mongod mongod mongod Sahrd5 mongod mongod mongod Sahrd6 Query Router Read/Write Operations Mongo DB Cluster MongoDB Production Overview
  • www.edureka.in/mongodbSlide 15 Introduction MongoDB provides rich functionalities for reading and manipulating data. CRUD stands for Create, Read, Update and Delete. These terms are the basic stuffs for all interactions with the databases. C R U D MongoDB CRUD Introduction
  • www.edureka.in/mongodbSlide 16 CRUD C R U D Create Read Update Delete MongoDB CRUD Operations
  • www.edureka.in/mongodbSlide 17 Data Operations Data Modification Query Database Operations Read Create Update Delete
  • www.edureka.in/mongodbSlide 18 CRUD Concepts Read Operations Write Operations MongoDB CRUD Concepts
  • www.edureka.in/mongodbSlide 19 Read Operations Cursors Query Optimization Query Plans Distributed Queries Read Operations
  • www.edureka.in/mongodbSlide 20 CURSORS Queries return iterable objects, called cursors, that hold the full result set of the query request. db.collection.find() method queries a collection and returns a cursor to the returning documents. To access the documents, you need to iterate the cursor. If the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times. > db.runCommand( { cursorInfo: 1 } ) is used to find information about cursor. CURSORS
  • www.edureka.in/mongodbSlide 21 > db.runCommand( { cursorInfo: 1 } ) > db.runCommand<{ cursor Info : 1 } > { “ totalOpen”: 0, “ client Cursors_size”:0, “timedout”: 0, “ok” :1} > > db.runCommand( { cursorInfo: 1 } ) > db.runCommand<{ cursor Info : 1 } > { “ totalOpen”: 1, “ client Cursors_size”:1, “timedout”: 0, “ok” :1} > Cursor Information
  • www.edureka.in/mongodbSlide 22 > Create an Index to Support Read Operations > Query Selectivity > Covering a Query > Query Plans Query Optimization
  • www.edureka.in/mongodbSlide 23 Query Behavior All queries in MongoDB address a single collection. You can modify the query to impose limits, skips, and sort orders. The order of documents returned by a query is not defined and is not defined unless you specify a sort(). Operations that modify existing documents (i.e. updates) use the same query syntax as queries to select documents to update. MongoDB provides a db.collection.findOne() method as a special case of find() that returns a single document. In aggregation pipeline, the $match pipeline stage provides access to MongoDB queries. Query Behavior
  • www.edureka.in/mongodbSlide 24 Annie’s Question When Query Plan Revision happens?
  • www.edureka.in/mongodbSlide 25 Annie’s Answer • The collection receives 1,000 write operations. • The reIndex rebuilds the index. • You add or drop an index. • The mongod process restarts.
  • www.edureka.in/mongodbSlide 26 Annie’s Question How do I isolate cursors from intervening write operations?
  • www.edureka.in/mongodbSlide 27 Annie’s Answer MongoDB cursors can return the same document more than once in some situations. You can use the snapshot() method on a cursor to isolate the operation for a very specific case.
  • www.edureka.in/mongodbSlide 28 Read Operations to Replica Sets Read Operations to Sharded Clusters Distributed Query Distributed Queries
  • www.edureka.in/mongodbSlide 29 app server app server app serverapp server Mongos Mongos Mongos Config 1 Config 2 Config 3 mongod mongod mongod Sahrd1 mongod mongod mongod Sahrd2 mongod mongod mongod Sahrd3 mongod mongod mongod Sahrd4 mongod mongod mongod Sahrd5 mongod mongod mongod Sahrd6 Query Router Read/Write Operations Mongo DB Cluster Sharded Collection Read Operations to Sharded Clusters
  • www.edureka.in/mongodbSlide 30 Sahrd1 Sahrd1 Secondary Primary Secondary Secondary Primary Secondary Config 1 Config 2 Config 3 app server MongosQuery Router Read Operations Write Operations Mongo DB Cluster Read Operations to ReplicaSet
  • www.edureka.in/mongodbSlide 31 Write Operations Write Operations Write Concern Write Operation Performance Record Padding Distributed Write Operations Bulk Inserts in MongoDB
  • www.edureka.in/mongodbSlide 32 With stronger write concerns, clients wait after sending a write operation for MongoDB to confirm the write operations. In some failure cases, write operations issued with weak write concerns may not persist. When inserts, updates and deletes have a weak write concern, write operations return quickly. The strength of the write concerns determine the level of guarantee. Write concern describes the guarantee that MongoDB provides when reporting on the success of a write operation.. Success Write Concerns
  • www.edureka.in/mongodbSlide 33 Write Concern Levels Errors Ignored Unacknowledged AcknowledgedJournaled Replica Acknowledged Write Concerns Levels
  • www.edureka.in/mongodbSlide 34  With an errors ignored write concern, MongoDB does not acknowledge write operations.  With this level of write concern, the client cannot detect failed write operations.  These errors include connection errors and mongod exceptions such as duplicate key exceptions for unique indexes.  Although the errors ignored write concern provides fast performance, this performance gain comes at the cost of significant risks for data persistence and durability.  To set errors ignored write concern, specify w values of -1 to your driver. db.addresses.ensureIndex( { "user_id": 1 }, { unique: true } ) Error Ignored
  • www.edureka.in/mongodbSlide 35  With an unacknowledged write concern, MongoDB does not acknowledge the receipt of write operation.  Unacknowledged is similar to errors ignored; however, drivers attempt to receive and handle network errors when possible.  Write operation to a mongod instance with write concern of unacknowledged.  The client does not wait for any acknowledgment. Driver mongod Write Apply Unacknowledged
  • www.edureka.in/mongodbSlide 36  With a receipt acknowledged write concern, the mongod confirms the receipt of the write operation.  Acknowledged write concern allows clients to catch network, duplicate key, and other errors.  To set acknowledged write concern, specify w values of 1 to your driver.  MongoDB uses acknowledged write concern by default, after the releases outlined in Default Write Concern Change.  Write operation to a mongod instance with write concern of acknowledged.  The client waits for acknowledgment of success or exception. Acknowledged
  • www.edureka.in/mongodbSlide 37 Driver mongod Write Apply getLastErrorW:l getLastError Response Acknowledged
  • www.edureka.in/mongodbSlide 38  With a journaled write concern, the mongod acknowledges the write operation only after committing the data to the journal.  This write concern ensures that MongoDB can recover the data following a shutdown or power interruption.  To set a journaled write concern, specify w values of 1 and set the journal or j option to true for your driver.  With a journaled write concern, write operations must wait for the next journal commit.  To reduce latency for these operations, you can increase the frequency that MongoDB commits operations to the journal.  The mongod sends acknowledgment after it commits the write operation to the journal. Journaled
  • www.edureka.in/mongodbSlide 39 Driver mongod Write Apply getLastErrorj:true getLastError Response Write to Journal Journaled
  • www.edureka.in/mongodbSlide 40  Replica sets add several considerations for write concern.  Basic write concerns affect write operations on only 1 mongod instance.  The w argument to getLastError provides replica acknowledged write concerns.  With replica acknowledged you can guarantee that the write operation propagates to the members of a replica set.  To set replica acknowledged write concern, specify w values greater than 1 to your driver. Replica Acknowledged
  • www.edureka.in/mongodbSlide 41 Driver Primary Write ApplygetLastErrorW:2 getLastError Response Secondary Secondary Replicate Replica Acknowledged
  • www.edureka.in/mongodbSlide 42 Write Operations Performance Document Growth JournalingIndexes Storage Performance Write Operation Performance
  • www.edureka.in/mongodbSlide 43 Annie’s Question What is record padding?
  • www.edureka.in/mongodbSlide 44 Annie’s Answer Padding is a process to minimize document movements.
  • www.edureka.in/mongodbSlide 45 String: Used to store the string data. String in mongodb must be UTF-8 valid. Arrays: This type is used to store arrays or list or multiple values into one key. Object: This datatype is used for embedded documents. Code: To store javascript code into document. Time Stamp: For recording when a document has been modified or added. Integer: For numerical value. Integer can be 32 bit or 64 bit depending upon your server. Boolean: For a Boolean (true/ false) value. Double: For floating point values. Regular expression: To store regular expression. Null: This type is used to store a Null value. Date: For current date or time in UNIX time format. Can specify your own date time by creating object of Date and passing day, month, year into it. Min/ Max keys: To compare a value against the lowest and highest BSON elements. Symbol: It's generally reserved for languages that use a specific symbol type. Object ID: Store the document’s ID. Binary data: To store binay data. MongoDB Data types
  • www.edureka.in/mongodbSlide 46  Insert Documents  Query Documents  Limit Fields to Return from a Query  Iterate a Cursor in the mongo Shell  Analyze Query Performance  Modify Documents  Remove Documents  Perform Two Phase Commits  Create Tailable Cursor  Isolate Sequence of Operations  Create an Auto-Incrementing Sequence Field  Limit Number of Elements in an Array after an Update MongoDB CRUD Syntax & Queries
  • www.edureka.in/mongodbSlide 47 MongoDB CRUD Operation- Live Demo
  • www.edureka.in/mongodbSlide 48 Annie’s Question What is two phase commit?
  • www.edureka.in/mongodbSlide 49 Annie’s Answer This is used to ensure immediate consistency and reliability.
  • www.edureka.in/mongodbSlide 50 Your Questions
  • www.edureka.in/mongodbSlide 51  http://en.wikipedia.org/wiki/Create,_read,_update_and_delete  http://docs.mongodb.org/manual/crud/  http://en.wikipedia.org/wiki/Crud  http://openmymind.net/mongodb.pdf  http://www.lornajane.net/posts/2011/simple-crud-with-mongodb  http://www.beingjavaguys.com/2013/08/mongo-db-crud-operations.html Further Reading
  • www.edureka.in/mongodbSlide 52 Tasks for you Attempt the following Assignments using the documents present in the LMS: How to iterate a Cursor in the mongo Shell? How to close Inactive Cursors? What is Tailable Cursor? How can you create an Auto-Incrementing Sequence Field? What is Record Padding? How many methods are there to insert document in Collection? What is _id field in MongoDB? What all the operators are there in MongoDB What is capped collection? What is CRUD? Assignments
  • www.edureka.in/mongodbSlide 53 Generate Test Data on MongoDB Database Execute all Module2 Script present in LMS Read FAQ Module2 in LMS Take Quiz in LMS for Module2 Complete assignment Pre-work: Module 2
  • www.edureka.in/mongodbSlide 54 Agenda of the Next Class  Data Modeling Concepts  Type of Data Modeling  Why Data Modeling ?  Data Modeling Approach  Analogy Between RDBMS & MongoDB Data Model  MongoDB Data Model  Challenges for Data Modeling in MongoDB  Data Model Examples and Patterns  Data Model References  Use Case of Data modeling Module 3 Schema Design and Data Modeling
  • www.edureka.in/mongodbSlide 55 What’s within the LMS Click here to expand and view all the elements of this Module
  • www.edureka.in/mongodbSlide 56 What’s within the LMS Recording of the Class Presentation Scripts Assignment
  • www.edureka.in/mongodbSlide 57 What’s within the LMS Further Reading Pre-work Quiz FAQ
  • Thank You See You in Class Next Week