Overview on NoSQL and MongoDB

29
NOSQL AND MONGO DB Haritha K

description

Overview on NoSQL and MongoDB

Transcript of Overview on NoSQL and MongoDB

Page 1: Overview on NoSQL and MongoDB

NOSQL AND MONGO DB

Haritha K

Page 2: Overview on NoSQL and MongoDB

What is NoSQL ?

Page 3: Overview on NoSQL and MongoDB

NoSQL

Page 4: Overview on NoSQL and MongoDB

NoSQL

Page 5: Overview on NoSQL and MongoDB

Types of NoSQL

Page 6: Overview on NoSQL and MongoDB

Philosophy of NoSQL

“One size fits all” no longer applies

“Non relational” DBs are more scalable, especially horizontally

Focus on speed, performance, flexibility, scalability

Not concerned with transactional stuff and relational semantics

DBs should be on-demand commodity, in a cloud like fashion.

Page 7: Overview on NoSQL and MongoDB

Examples of NoSQL

Page 8: Overview on NoSQL and MongoDB

CAP theorem

Statement: One can only have two of Consistency, Availability, and tolerance to network Partitions at the same time.

Consistency (all nodes see the same data at the same time)

Availability (a guarantee that every request receives a response about whether it was successful or failed)

Partition tolerance (the system continues to operate despite arbitrary message loss or failure of part of the system)

Page 9: Overview on NoSQL and MongoDB

CAP theorem

Page 10: Overview on NoSQL and MongoDB

Mongo DB

Page 11: Overview on NoSQL and MongoDB

How popular is MongoDB?

Page 12: Overview on NoSQL and MongoDB

MONGO DB

Humongous ( Huge + monstrous )

A document model NoSQL DB

Has all advantages of NoSQL

Data modeling matches application objects

Fits better with object oriented programming

Schema-free,fast and scalable

Developed and supported by 10gen.First release – Feb 2009,latest – Aug 2014.

Page 13: Overview on NoSQL and MongoDB

How data is stored?

Page 14: Overview on NoSQL and MongoDB

How data is stored?

Page 15: Overview on NoSQL and MongoDB

How data is stored?

Page 16: Overview on NoSQL and MongoDB

BSON – Binary JSON

Documents are stored in BSON format

BSON is a binary serialization of JSON like objects

This is extremely powerful as Mongo understands JSON natively

Any valid JSON can be easily imported and queried.

Schema-less and flexible.

Page 17: Overview on NoSQL and MongoDB

Terminology

SQL Terms/Concepts MongoDB Terms/Concepts

database database

table collection

row document or BSON document

column Field

index Index

table joins embedded documents and linking

primary key primary key

Specify any unique column or column combination as

primary key.

Holds a document’s primary key which is usually a BSON

object

Page 18: Overview on NoSQL and MongoDB

Data Modification – Insert

Data modifictions refers to operations that create,update or delete data

In MongoDB, these operations modify the data of a single collection.

For the update and delete operations, criteria can be specified.

Page 19: Overview on NoSQL and MongoDB

Update and Save

The db.collection.update() method can accept query criteria to determine which documents to update as well as an option to update multiple rows.

Format : db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA,

UPDATED_DATA)

db.inventory.update( { name:“jack"}, {$inc:{age:-1}}, {multi:true})

The db.collection.save() method can replace an existing document.

Format : db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA})

db.inventory.save( {_id: ObjectId("540451f745fa71ef2dd18c85"),"empId" : 3333,

“dept" : "sales"} )

Page 20: Overview on NoSQL and MongoDB

Read

Read operations or queries will retrieve the data stored in the database.

Queries selects documents from a single collection.

The db.collection.find() method accepts query criteria and projections and returns a cursor to the matching documents.

Format : db.collection.find(<criteria>, <projection>)

db.inventory.find({},{KEY:1})

db.inventory.find({name:"a"},{age:true})

db.inventory.find( {tags:"machine"}) db.inventory.find( {tags:"machine"}).limit(1)

db.inventory.findOne().tags

Page 21: Overview on NoSQL and MongoDB

Remove

Remove method to remove documents from a collection.

Format: db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)

Can remove all documents from a collection

db.inventory.remove()

Remove all documents matching a condition.

db.inventory.remove( {test:"ok"} )

Limit the operation to remove just a single document.

db.inventory.remove( {test:"ok"},1 )

Page 22: Overview on NoSQL and MongoDB

Replication

Page 23: Overview on NoSQL and MongoDB

Replication & Read Preferences

Page 24: Overview on NoSQL and MongoDB

Sharding

Page 25: Overview on NoSQL and MongoDB

Sharding & Distributed Queries

Page 26: Overview on NoSQL and MongoDB

Write Concerns

Stronger settings: slower, better guarantee

Errors Ignored

Acknowledged

Unacknowledged

Journaled

Replica Acknowledged

Page 27: Overview on NoSQL and MongoDB

Write Concerns

Page 28: Overview on NoSQL and MongoDB

Disadvantages of NoSQL

No common standards. Each database does things differently.

Querying data does not involve familiar SQL model to find records.

NoSQL databases are relatively immature and constantly evolving.

Because a NoSQL database avoids ACID (Atomicity, Consistency, Isolation, Durability) model, there is no guarantee that all of the data will be success

Page 29: Overview on NoSQL and MongoDB

Thank You………..