MongoDB

576 views
334 views

Published on

Mongo database as kind of Document database

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

  • Be the first to like this

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

No notes for slide

MongoDB

  1. 1. Web Data Management, Search and Retrieval Course (MCOM7348) University of Birzeit, Palestine January, 2014 Synthesis Paper Talk Nosql Database Fayez shayeb bbbbb Master of Computing, Birzeit University Fayez.aauj@hotmail.com Master of Computing, Birzeit University bbbbbbb@yahoo.com This is a student talk, at the Web Data Management, Search and Retrieval Course, each student is is asked to present his/her synthesis paper. Course Page: http://jarrar-courses.blogspot.com/2013/11/web-data-management.html 1
  2. 2. Document-oriented database • document-oriented database is a computer program designed for storing, retrieving, and managing document-oriented, or semi structured data, information
  3. 3. Comparison  Document db  Relational Article - id - authorid - title - content Author - id - name - email Comment - id - articleid - message Article - _id - title - content - author - _id - name - email - comments[]
  4. 4. Concepts  Joins  No joins  Joins at "design time", not at "query time“  Due to embedded docs and arrays less joins are needed  Constraints  No foreign key constraints  Unique indexes  Transactions  No commit/rollback  Atomic operations  Multiple actions inside the same document  Incl. embedded documents
  5. 5. Benefits  Scalable: good for a lot of data / traffic  Horizontal scaling: to more nodes  Good for web-apps  Performance  No joins and constraints  Dev/user friendly  Data is modeled to how the app is going to use it  No conversion between object oriented > relational  No static schema = agile
  6. 6. One-to-many  Embedded array / array keys  Some queries get harder  You can index arrays!  Normalized approach  More flexibility  A lot less performance Article - _id - content - tags: {“foo”, “bar”} - comments: {“id1”, “id2”}
  7. 7. many-to-many  Using array keys  No join table  References on both sides Article - _id - content - category_ids : {“id1”, “id2”} Category - _id - name - article_ids: {“id7”, “id8”}  Advantage: simple queries articles.Where(p => p.CategoryIds.Contains(categoryId)) categories.Where(c => c.ArticleIds.Contains(articleId))  Disadvantage: duplication, update two docs
  8. 8. json • • • Stands for Javascript Object Notation Derived from Javascript scripting language Used for representing simple data structures and associative arrays { { "_id": "BCCD12CBB", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true } "_id": "BCCD12CBC", "type": "person", "name": "Luke", "age": 35, "powers": ["Pull", "Jedi Mind Trick"], "dark_side": false }
  9. 9. Replication  Only one server is active for writes (the primary, or master) at a given time – this is to allow strong consistent (atomic) operations. One can optionally send read operations to the secondaries when eventual consistency semantics are acceptable.
  10. 10. Sharding  Sharding is the partitioning of data among multiple machines in an order-preserving manner.(horizontal scaling ) Machine 1 Machine 2 Machine 3 Alabama → Arizona Colorado → Florida Arkansas → California Indiana → Kansas Idaho → Illinois Georgia → Hawaii Maryland → Michigan Kentucky → Maine Minnesota → Missouri Montana → Montana Nebraska → New Jersey Ohio → Pennsylvania New Mexico → North Dakota Rhode Island → South Dakota Tennessee → Utah Vermont → West Virgina Wisconsin → Wyoming
  11. 11. Sharding  The set of servers/mongod process within the shard comprise a replica set
  12. 12. Replication & Sharding conclusion  sharding is the tool for scaling a system, and replication is the tool for data safety, high availability, and disaster recovery. The two work in tandem yet are orthogonal concepts in the design.
  13. 13. Document Databases
  14. 14. What is MongoDB?  Creator: 10 gen, former doublick  Name: short for humongous (  Language: C++ )
  15. 15. What is MongoDB?  Defination: MongoDB is an open source, document- oriented database designed with both scalability and developer agility in mind. Instead of storing your data in tables and rows as you would with a relational database, in MongoDB you store JSON-like documents with dynamic schemas(schemafree, schemaless).
  16. 16. What is MongoDB?  Goal: bridge the gap between key-value stores (which are fast and scalable) and relational databases (which have rich functionality).
  17. 17. MongoDB terms ?
  18. 18. Term mapping
  19. 19. MongoDB Data model  Data model: Using BSON (binary JSON), developers can easily map to modern object-oriented languages without a complicated ORM layer.  BSON is a binary format in which zero or more key/value pairs are stored as a single entity.  lightweight, traversable, efficient
  20. 20. Schema design  RDBMS: join
  21. 21. Schema design
  22. 22. Schema design
  23. 23. Query MongoDB Vs sql? SQL mongodb Create table db.CreateCollection() Insert into db.coll.save() select db.coll.find() update db.coll.update delete db.coll.remove() drop db.coll.drop()
  24. 24. Query MongoDB Vs sql?
  25. 25. Query MongoDB Vs sql?
  26. 26. API for MongoDB : C C++ C# Erlang Haskell Java node.js PHP Perl Python Ruby Scala (Casbah)
  27. 27. Thank You 27

×