Introduction to NOSQL And MongoDB

2,939 views

Published on

Published in: Technology
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total views
2,939
On SlideShare
0
From Embeds
0
Number of Embeds
101
Actions
Shares
0
Downloads
76
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Introduction to NOSQL And MongoDB

  1. 1. Introduction to NoSQLAnd MongoDBBehrouz Bakhtiari Farid Dehgan
  2. 2. ntroduction to NOSQL And MongoDBnes are correct? NOSQL = Not To SQL NOSQL = Not Only SQL
  3. 3. ntroduction to NOSQL And MongoDBHigh ThroughputReduce CostEliminate ORM Complexity
  4. 4. ntroduction to NOSQL And MongoDBHorizontal Scalability
  5. 5. ntroduction to NOSQL And MongoDBHorizontal Scalability“Oracle would tell you that with the right degree of hardware and the right configuration of Oracle RAC (Real Application Clusters) and otherassociated magic software, you can achieve the same scalability. But at what cost?”
  6. 6. ntroduction to NOSQL And MongoDBThe CAP-Theorem
  7. 7. ntroduction to NOSQL And MongoDBConsistency
  8. 8. ntroduction to NOSQL And MongoDBAvailability
  9. 9. ntroduction to NOSQL And MongoDBPartition Tolerance
  10. 10. ntroduction to NOSQL And MongoDB Not Available
  11. 11. ntroduction to NOSQL And MongoDB ACID Atomic Consistent Isolated Durable
  12. 12. ntroduction to NOSQL And MongoDBBASE Base Availability Soft-state Not durablual consistency e
  13. 13. ntroduction to NOSQL And MongoDBNOSQL Taxonomy Key-Value Stores Column Stores Document Stores Graph Databases
  14. 14. ntroduction to NOSQL And MongoDBKey-Value Stores Automobile Key Attributes 1 Make: Toyota Model: Highlander Color: Maroon Year: 2004 2 Make: Toyota Model: Highlander Color: Blue Year: 2005 Transmission: Automatic
  15. 15. ntroduction to NOSQL And MongoDBDynamo DB Amazon Key-Value Consistent Hashing
  16. 16. ntroduction to NOSQL And MongoDBColumnStores EmpId Lastname Firstname Salary 1 Smith Joe 40000 2 Jones Mary 50000 3 Johnson Cathy 44000 A Row-oriented Database: puts rows together 1,Smith,Joe,40000; 2,Jones,Mary,50000; 3,Johnson,Cathy,44000; A Column-oriented Database: puts values of a column together. 1,2,3; Smith,Jones,Johnson; Joe,Mary,Cathy; 40000,50000,44000;
  17. 17. ntroduction to NOSQL And MongoDBBigTable Sparse (rows only where there are values; not fixed length) Distributed (horizontally partitioned over many servers) Multidimensional (consisting of a multi-part key)
  18. 18. ntroduction to NOSQL And MongoDBMapReduce
  19. 19. ntroduction to NOSQL And MongoDBGraph Databases
  20. 20. ntroduction to NOSQL And MongoDBGraph Vs. Key-Value
  21. 21. ntroduction to NOSQL And MongoDBJSON
  22. 22. ntroduction to NOSQL And MongoDBDocuments Documents = Rows In MongoDB the documents are conceptually JSON. documents can be thought of as objects but only the data of an object, not the code, methods or class hierarchy MongoDB is type-sensitive and case-sensitive. {“foo” : 3} # {“foo” : “3”} Or {“foo” : 3} # {“Foo” : 3}
  23. 23. ntroduction to NOSQL And MongoDBCollections Collections = Tables A MongoDB collection is a collection of BSON documents. Collections are schema-free. A collection is created when the first document is inserted. The maximum size of a collection name is 128 characters (including the name of the db and indexes).
  24. 24. ntroduction to NOSQL And MongoDBGetting and Starting MongoD Default port for serverTo start the server, run the mongod executable. Default data directory : C:datadb If directory.exist(“C:datadb”) == false then server.fail > mongod --dbpath D:data
  25. 25. ntroduction to NOSQL And MongoDBMongoDB ShellI want to interact with MongoDB > mongo make sure you start mongod before starting the shell. > X = 200 > Math.sin(Math.PI / 2 ); 200 1 >X/5 > “TOSS”.replace(“T”,”Tabriz ”); 40 Tabriz OSS
  26. 26. ntroduction to NOSQL And MongoDBCreating Documents> db.post.insert({ID: 1,Title:“TDD",Body:"Unit Test"})> db.post.insert({ID: 2,Title:"NOSQL",Body:"Introduction to NOSQL",Authors:["Farid"]})> db.post.insert({ID: 3,Title:"MongoDB",Body:"Introduction to MongoDB",Authors:["Farid",“Behrouz"]}) Mapping To Relational Modal Post PostAuthors Authors> INSERT INTO Authors ( ID , Name) Values ( 1 , Behrouz )> INSERT INTO Authors ( ID , Name) Values ( 2 , Farid )> INSERT INTO post ( ID , Title , Body ) Values ( 3 , MongoDB „ , Introduction to MongoDB )> INSERT INTO PostAuthors (Post ID , AuthorID) Values ( 3 , 1)> INSERT INTO PostAuthors (Post ID , AuthorID) Values ( 3 , 2)
  27. 27. ntroduction to NOSQL And MongoDBDeleting Documents > DELETE FROM post > db.post.remove() > DELETE FROM post WHERE ID = 1 > db.post.remove({ ID : 1 }) > DELETE FROM post WHERE ID = 1 AND Title = „TDD‟ > db.post.remove({ ID : 1 , Title : " TDD " })
  28. 28. ntroduction to NOSQL And MongoDBUpdating Documents> UPDATE post SET Title = „Mocking‟ Where ID = 1 Updates, update by default only the first documents that matches the criteria.> db.post.update( { ID: 1 } , { "$set" : {Title : "Mocking“ } } )> db.post.update( { ID: 1 } , { "$set" : {Title : "Mocking“ } } ,false , true) Upsert ?
  29. 29. ntroduction to NOSQL And MongoDBUpdating Documents> db.post.update( { ID: 1o1 } , { "$set" : { Title : “Scrum“ , Body : “Scrum” } } , true) Yes Exist this document Update document No Create a new document {ID : 101}
  30. 30. ntroduction to NOSQL And MongoDBUpdating Documents> db.post.update( {ID : 3 } , { "$set" : { comments : [{ Email : "behrouzlo@yahoo.com" , Body : "Test“ }]}}) Mapping To Relational Modal Post Comments 1 * > INSERT INTO comments ( postID , Email , Body ) VALUES ( 3 , ‟behrouzlo@yahoo.com‟ , ‟Test‟ )
  31. 31. ntroduction to NOSQL And MongoDBQuerying> SELECT * FROM post> db.post.find()> SELECT ID , Title FROM post The _id key is always returned, even if it isn‟t specifically listed.> db.post.find({} , { ID : 1 , Title : 1 })> db.post.find({} , { ID : 1 , Title : 1 , _id : 0 })
  32. 32. ntroduction to NOSQL And MongoDBQuerying> SELECT * FROM post WHERE ID = 1> db.post.find({ ID : 1 })> SELECT * FROM post WHERE ID = 1 OR ID = 3> db.post.find( { “$or” : [{ ID = 1 } , { ID = 3 } ] } )
  33. 33. ntroduction to NOSQL And MongoDBQuerying$lt < $lte <= $gt > $gte >= $ne <>> SELECT * FROM post WHERE ID >= 1 And ID <= 100> db.post.find ( { ID : { “$gte” : 1 , “$lte” : 100 } } )> SELECT * FROM post WHERE ID <> 1> db.post.find ( { ID : { “$ne” : 1} } )
  34. 34. ntroduction to NOSQL And MongoDBQuerying> SELECT * FROM post WHERE ID = 1> db.post.find({ ID : 1 })> SELECT * FROM post WHERE ID = 1 OR ID = 3> db.post.find( { “$or” : [{ ID = 1 } , { ID = 3 } ] } )
  35. 35. ntroduction to NOSQL And MongoDBQuerying> SELECT * FROM post ORDER BY ID> db.post.find().sort ( { ID : 1 } )> SELECT * FROM post ORDER BY ID DESC> db.post.find().sort ( { ID : -1 } )
  36. 36. ntroduction to NOSQL And MongoDB

×