You are on page 1of 51

NO SQL

Shinto Philip

TOPICS
Big Data NoSQL JSON Introduction to MongoDB

BIG DATA

Big Users

Not that long ago, 1,000 daily users of an application was a lot Today, with the growth in global Internet use, it's not uncommon for apps to have millions of users a day.. The increased number of hours users spend online. The growing popularity of smart phones and tablets.

So we need more scalable data bases

BIG Data

Every day, we create 2.5 quintillion bytes of data so much that

90% of the data in the world today has been created in the last two years alone.
This data comes from Sensors used to gather climate information Posts to social media sites Digital pictures and videos Purchase transaction records, and. Cell phone GPS signals to name a few.

This data is

big DATA.

BIG Data

BIG Data

Developers want very flexible database that

Easily accommodates new data types and


Isnt disrupted by content structure changes from third-party data providers.

Solution????...??

NO SQL

NO SQL

Non relational

Features

Scalability o Vertically Add more data o Horizontally Add more storage No pre-defined schema No join operations(We just have pointers) NoSQL = Not Only SQL No declarative query language more programming Relaxed consistency fewer guarantees

CAP not ACID

Consistency Availability Partitioning (but not all three at once!)

MongoDB is recognized as the leading NoSQL database


ACID Atomicity, Consistency, Isolation and Durability.

Advantages
Cheap, easy to implement
Data are replicated and can be partitioned. Easy to distribute Can scale up and down Quick process of large amount of data. Can handle web-scale data, whereas Relational DBs cannot.

Why No SQL?

RDBMS

The relational model takes data and separates it into many


interrelated tables that contain rows and columns. Use of Primary keys and Foreign keys. . . Need Join operations

NO SQL
Schema less No need of JOIN operations, primary keys and foreign keys FASTER ACCESS

Example

Scalability and Performance advantages

Scale up
A centralized approach that relies on bigger and bigger servers.

Scale Out
A distributed approach that leverages many standard, commodity physical or virtual servers. NoSQL databases were developed from the ground up to be distributed, scale out databases. Theres no need to modify the application as you scale since the application always sees a single (distributed) database.

scale out

Characteristics
Auto-sharding - If load increases (more storage space, more processing

power), it can be distributed to other nodes across computer networks.


- Automatically spreads data across servers, without requiring applications to participate. - Most NoSQL databases also support data replication

Integrated caching To reduce latency and increase sustained data throughput, advanced NoSQL database technologies transparently cache data in system memory.

NoSQL Database Types

Types of NoSQL

Key-value stores The simplest NoSQL databases. Every single item in the database is stored as an attribute name, or key, together with its value. Examples : Riak, Voldemort, BigTable. Document databases pair each key with a complex data structure known as a document.

Documents can contain many different key-value pairs, or key-array pairs, or even nested documents.
Example: MongoDB

Types of NoSQL

Wide-column stores Cassandra and HBase are optimized for queries over large datasets, and store columns of data together, instead of rows. Graph stores Used to store information about networks, such as social connections. Examples: Neo4J and HyperGraphDB

References

http://www.zdnet.com/what-is-nosql-and-why-do-you-need-it7000004989/ http://www.couchbase.com/why-nosql/nosql-database https://en.wikipedia.org/wiki/NoSQL http://nosql-database.org/

JSON - Java Script Object Notation

Shinto Philip

What is JSON??

JSON is a data interchange format AJAX: Data transfer without refreshing a page. JSON is a subset of Java Script. JSON can be parsed by a Java Script parser. It can represent either complex or simple data as it has data types They are Strings, Number, Boolean, Objects and Arrays

Comparing
XML <person> <age>12</age> <name>Danielle</name> </person>

JSON myJSON = {"age" : 12, "name" : "Danielle"}

Values in JSON can be..

value string number object array


true false null

Strings
Sequence of 0 or more Unicode characters. No separate character type. A character is represented as a string with a length of 1. Wrapped in "double quotes. Backslash escapement.

Strings

string
"

Any UNICODE character except " or \ or control character


\ " \ / b f n r t u

"

quotation mark reverse solidus solidus backspace formfeed newline carriage return horizontal tab 4 hexadecimal digits

Numbers
Integer Real Scientific

No octal or hex
No NaN or Infinity - Use null instead

Numbers

number
0 .

digit

digit 1 - 9 digit

e E +

digit
-

Booleans

true false

Null
A value that isn't anything

Object
Objects are unordered containers of key/value pairs Objects are wrapped in { } , separates key/value pairs : separates keys and values Keys are strings Values are JSON values
object
{

string

: ,

value

Example for an object

"name": "Jack B. Nimble", "at large": true, "grade": "A", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "framerate": 24 }
}

Arrays
Arrays are ordered sequences of values Arrays are wrapped in [] , separates values

JSON does not talk about indexing. An implementation can start array indexing at 0 or 1.
value
,

array
[ ]

Arrays:Example

["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] [

[0, -1, 0], [1, 0, 0], [0, 0, 1]


]

Arrays:Example

JSON has no version number. No revisions to the JSON grammar are anticipated. JSON is very stable.

MIME Media Type

application/json

More. . .

JSON response at client side is: var name = eval('(' + req.responseText + ')').fullname.value; To access a composite element eval('(' + req.responseText + ')').xyz.abc.value; Thus, any level deep elements can be easily accessed.

References

http://www.mongodb.org/ http://www.mkyong.com/tutorials/java-mongodb-tutorials/

Shinto Philip

Introduction
Open Source database written in C++. DOCUMENT ORIENTED DATABASE Uses a document model, which can be thought of as a row in a RDBMS. Documents, a set of fields (key-value pairs) map nicely to programming language data types. A MongoDB database holds a collection which is a set of documents. Embedded documents and arrays reduce need for joins, which is key for high performance and speed.

Sharding

ConfigD ConfigD ConfigD

MongoD MongoD MongoD

MongoD MongoD MongoD

MongoD MongoD MongoD

MongoD MongoD MongoD

Insertion

db.tablename.insert({data}) or db.tablename.save({data}).

Example: > db.userdetails.insert({ "user_id : "xyz123 , "password" : "xyz123" })

Update

To update a record, uses db.tablename.update({criteria} , {$set: {new value} }).

Example: >db.users.update({username:"mkyong"},{$set:{password:"hello1 23"}})

Delete

db.tablename.remove({criteria})

Example: >db.userdetails.remove( { "user_id" : "testuser" } )

Fetching

db.tablename.find( {criteria} ).

Example: >db.userdetails.find({"education":"M.C.A."})

APIs available in Java

References

http://www.mongodb.org/ http://www.mkyong.com/tutorials/java-mongodb-tutorials/

You might also like