No SQl



 - Nishant Shrivastava

nishant.nightcrawler@gmail.com

github : nishant-shrivastava

twitter  : n1shant


No sql



Not Only SQL


Motto :

Code : 
$ SELECT fun, profit from `real_world` WHERE `relational` = false;



No Sql : Types



  •  Wide column store / Column Families
  • Key Value / Tuple Store
  • Graph Database
  • Document Store

Wide Column Store / Column Families


 - Created to store and process very large amounts of data distributed over many machines.

- Still uses keys but they point to multiple columns.

- The columns are arranged by column family.

Examples : 

  • Hadoop / HBase
  • Cassandra
  • Amazon SimpleDB

Key Value / Tuple Store


 - The idea here is using a hash table where there is a unique key and a pointer to a particular item of data.
     - The Key/value model is the simplest and easiest to implement.
   - But it is inefficient when you are only interested in querying or updating part of a value, among other disadvantages.
Example :
  • DynamoDB
  • Azure Table Storage
  • Riak
  • Redis

Graph DAtabase

- Instead of tables of rows and columns and the rigid structure of SQL, a flexible graph model is used which, again, can scale across multiple machines.

 - NoSQL databases do not provide a high-level declarative query language like SQL to avoid overtime in processing.

 - Rather, querying these databases is data-model specific.

Example :

  • Neo4J
  • BigData
  • InfoGrid

Document Databases

- Inspired by Lotus Notes

 - Similar to key-value stores.
 - The model is basically versioned documents that are collections of other key-value collections.

 - The semi-structured documents are stored in formats like JSON.

 - Document databases are essentially the next level of Key/value, allowing nested values associated with each key.

- Document databases support querying more efficiently.

Example :

  • MongoDB
  • CouchDB

4-Fundamentals

  • BSON Documents
    • MongoDB is a document-based database system, and as a result, all records, or data, in MongoDB are documents.
    • The records are stored in Collections
  • Object Id 
    • 12 byte BSON Type
    • a 4-byte value representing seconds since the Unix epoch
    • 3-byte machine identifier
    • 2-byte process id
    • 3-byte counter  

4-fundamentals...

  • GridFS
    • It is a specification for Storing and Retrieving files that exceeds BSON-document size  limit of 16MB.
    • Instead of storing a file in a single document, GridFS divides a file into parts, or chunks, and stores each of those chunks as a separate document.

  • Database References
    • MongoDB does not support Joins
    • In MongoDB some data is denormalized  or stored  with related data  in documents to remove the need for  joins.

Mongo DB

- By 10Gen

- In simple words, it is a Document Oriented Database
- Writes the data in Flat Files in BSON Format
(similar to JSON format)



  • Scalable
  • Open Source
  • High Performance
  • Document Oriented database

Mongo DB

 - In 1970's , Flat file system was created
: Problem - No Standard Implementation

- Relational Database was the answer
- Standardized implementation, as per the Relational theory given in 1969 by Codd.

- Relational Databases were the answers until the data became

BIG

Storage

                    : RDBMS

  • Tables

                   : NoSQL

  • Collection

Schema



                    : RDBMS 
  • Schema 
    • Record
      • Field

                    : NoSql
  • Collection
    • Document
      • KeyValuePair

mongo db

  • Connecting to Mongo
    • mongo
      • (runs as mongod)

  • Show Databases
    • $ show dbs

  • Use Database
    • $ use myDb

  • Next is CRUD operations....

Inserting

$ user1 = { first_name : "Nishant" , last_name : "Shrivastava"} ;$ user2 = { first_name : "Bruce" , last_name : "Wayne"} ; 
$ db.users.insert(user1); $ db.users.insert(user2);

  • Confirming that collection exists

 $ show collections; 
  • Confirming that document exists in users collection

 $ db.users.find();

Collection

 $ {      "_id" : ObjectId("4c2209f9f3924d31102bd84a") ,       "first_name" : "Nishant" ,       "last_name" : "Shrivastava"   }   {      "_id" : ObjectId("4c2209fef3924d31102bd84b") ,       "first_name" : "Bruce",      "last_name" : "Wayne"   }

READ

  • find ()

 $ db.collection.find( <query>, <projection> )

UPDATE


  • update
- updates single document
- can use multi  option, can update all documents. 
 $ db.collection.update( <query>, <update>, <options> )
  • save

- performs a special type of update() , depending upon _id
 $ db.collection.save( <document> )

delete


  • remove ()

 $ db.collection.remove( <query>, <justOne> )




THank You!



References

- http://www.3pillarglobal.com/insights/exploring-the-different-types-of-nosql-databases

- http://en.wikipedia.org/wiki/NoSQL
Made with Slides.com