mongodb

27
1 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 Nosql Database Web Data Management, Search and Retrieval Course (MCOM7348) University of Birzeit, Palestine January, 2014 Synthesis Paper Talk Fayez shayeb Master of Computing, Birzeit University [email protected] bbbbb Master of Computing, Birzeit University [email protected]

Upload: fayez-shayeb

Post on 12-May-2015

240 views

Category:

Technology


1 download

DESCRIPTION

Mongo database as kind of Document database

TRANSCRIPT

Page 1: MongoDB

1

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

Nosql Database

Web Data Management, Search and Retrieval Course (MCOM7348)University of Birzeit, Palestine

January, 2014

Synthesis Paper Talk

Fayez shayeb

Master of Computing, Birzeit [email protected]

bbbbb

Master of Computing, Birzeit [email protected]

Page 2: MongoDB

• document-oriented database is a computer program designed for storing, retrieving, and managing document-oriented, or semi structured data, information

Document-oriented database

Page 3: MongoDB

Comparison

Article- id- authori

d- title- content

Comment- id- articlei

d- messa

ge

Author- id- name- email

Article- _id- title- content- author

- comments[]

Document db Relational

- _id- name- email

Page 4: MongoDB

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

Page 5: MongoDB

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

Benefits

Page 6: MongoDB

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”}

Page 7: MongoDB

many-to-many

Using array keys No join table

References on both sides

Advantage: simple queriesarticles.Where(p =>

p.CategoryIds.Contains(categoryId))categories.Where(c =>

c.ArticleIds.Contains(articleId)) Disadvantage: duplication, update two docs

Article- _id- content- category_ids : {“id1”,

“id2”}

Category- _id- name- article_ids: {“id7”,

“id8”}

Page 8: MongoDB

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}

Page 9: MongoDB

ReplicationOnly 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.

Page 10: MongoDB

ShardingSharding 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

Page 11: MongoDB

ShardingThe set of servers/mongod process within

the shard comprise a replica set

Page 12: MongoDB

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.

Page 13: MongoDB

Document Databases

Page 14: MongoDB

What is MongoDB?

Creator: 10 gen, former doublick

Name: short for humongous (عمالق)

Language: C++

Page 15: MongoDB

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(schema-free, schemaless).

Page 16: MongoDB

Goal: bridge the gap between key-value stores (which are fast and scalable) and relational databases (which have rich functionality).

What is MongoDB?

Page 17: MongoDB

MongoDB terms ?

Page 18: MongoDB

Term mapping

Page 19: MongoDB

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

MongoDB Data model

Page 20: MongoDB

Schema designRDBMS: join

Page 21: MongoDB

Schema design

Page 22: MongoDB

Schema design

Page 23: MongoDB

mongodb SQL

db.CreateCollection() Create table

db.coll.save() Insert into

db.coll.find() select

db.coll.update update

db.coll.remove() delete

db.coll.drop() drop

Query MongoDB Vs sql?

Page 24: MongoDB

Query MongoDB Vs sql?

Page 25: MongoDB

Query MongoDB Vs sql?

Page 27: MongoDB

27

Thank You