Download - Overview on NoSQL and MongoDB
NOSQL AND MONGO DB
Haritha K
What is NoSQL ?
NoSQL
NoSQL
Types of NoSQL
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.
Examples of NoSQL
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)
CAP theorem
Mongo DB
How popular is 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.
How data is stored?
How data is stored?
How data is stored?
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.
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
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.
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"} )
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
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 )
Replication
Replication & Read Preferences
Sharding
Sharding & Distributed Queries
Write Concerns
Stronger settings: slower, better guarantee
Errors Ignored
Acknowledged
Unacknowledged
Journaled
Replica Acknowledged
Write Concerns
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
Thank You………..