MongoDB

32
MongoDB By Rony Abraham Gregory Model Engineering College

description

A brief intro to MongDB.

Transcript of MongoDB

Page 1: MongoDB

MongoDB

ByRony Abraham Gregory

Model Engineering College

Page 2: MongoDB

What is MongoDB? • Humongous (huge + monstrous)• Document Database• Schema free• C++• Open Source

Page 3: MongoDB

What is MongoDB? • GNU AGPL v3.0 Licence• OSX, Linux, Windows, Solaris | 32

bit, 64 bit• Development and Support by 10gen and was first released in February 2009

• NoSQL!

Page 4: MongoDB

Database Paradigms • Relational (RDBMS)• NoSQLoKey-value storesoDocument databasesoWide column stores (BigTable

and clones)oGraph databases

Page 5: MongoDB

Relational Databases• ACID (Atomicity Consistency

Isolation and Durability)• SQL• MySQL, PostgreSQL, Oracle, etc.

Page 6: MongoDB

Key-value stores• “One key, one value, no duplicates

and very fast”• It’s a Hash!• The value is a binary object aka

“blob” – the DB doesn’t understand it and doesn’t want to understand it.

• Amazon Dynamo, MemcacheDB, etc.

Page 7: MongoDB

Key-value stores

Fig: A key-value store

Page 8: MongoDB

Document databases• Key-value stores, but the value is

(usually) structured and “understood” by the DB.

• Querying data is possible (by means other than just a key).

• Amazon SimpleDB, CouchDB, MongoDB, Riak, etc.

Page 9: MongoDB

Document databases

Fig: A document database

Page 10: MongoDB

Why NoSQL?• Schema-free• Massive data stores• Scalability• Some services simpler to

implement than using RDBMS• Great fit for many Web 2.0

applications

Page 11: MongoDB

Why NOT NoSQL?• RDBMSes and its tools are

mature• NoSQL implementations are

often in their “alpha” state• Data consistency, transactions• “Don’t scale until you need it”

Page 12: MongoDB

RDBMS vs NoSQL• Strong consistency vs Eventual

consistency• Big dataset vs HUGE dataset• Scaling is possible vs Scaling is

easy• Good availability vs Very high

availability

Page 13: MongoDB

RDBMS vs NoSQL• Strong consistency vs Eventual

consistency• Big dataset vs HUGE dataset• Scaling is possible vs Scaling is

easy• Good availability vs Very high

availability

Page 14: MongoDB

RDBMS vs NoSQL• Strong consistency vs Eventual

consistency• Big dataset vs HUGE dataset• Scaling is possible vs Scaling is

easy• Good availability vs Very high

availability

Page 15: MongoDB

Features• Standard database stuff• Indexing• Replication/failover support

Page 16: MongoDB

Features• Documents are stored in BSON

(JSON)• BSON is a Binary serialization of

JSON-like objects• This is extremely powerful, because

it means mongoDB understands JSON natively

• Any valid JSON can be easily imported and queried

Page 17: MongoDB

Features• Schema-less; very flexible• Auto-sharding (alpha)• Makes for easy horizontal;

scaling• Map/Reduce

Page 18: MongoDB

Features• Very, very fast• Super easy to install• Strong with major languages

Page 19: MongoDB

Features: Querying• Rich, JavaScript based query syntax• Allows us to do deep, nested queries

db.order.find( {shipping: { carrier:”usps” }} );

shipping is an embedded document (object)

Page 20: MongoDB

Features: Official Drivers• .NET, Java, JavaScript, Ruby,

Node.js, PHP, Haskell, C/C++, Perl

Page 21: MongoDB

Concepts: Document-Oriented• Think of “documents” as

objects/database records• Documents are basically just

JSON in binary• Ability to store information all

together

Page 22: MongoDB

Concepts: Document-Oriented

Page 23: MongoDB

Concepts: Document-Oriented

Concept Mapping

Page 24: MongoDB

Concepts: Cursors• Queries return “cursors” instead

of collections• A cursor allows you to iterate

through the result set• A big reason for this is

performance• Much more efficient than

loading all objects into memory

Page 25: MongoDB

Concepts: Cursors• The find() function returns a

cursor object

Page 26: MongoDB

Basic Operations• Insert• Find• Update• Remove• ensureIndex

Page 27: MongoDB

Basic Operations• Insertdb.test.insert({hello:’world’});• FindoEquivalent of Select * FROM

test;

Page 28: MongoDB

Basic Operations:Updatedb.test.update(<condition>,<operation>)

Page 29: MongoDB

Basic Operations: Removedb.test.remove(<condition>)

Page 30: MongoDB

Basic Operations: Indexing• Its usually a good idea to index

collections• How and which columns depend

on what is to be donedb.test.ensureIndex({hello:I})

Page 31: MongoDB

MongoDB in action!

Page 32: MongoDB

References• MongoDB home at http://www.mongodb.org • MongoDB - The Definitive Guide by Kristina

Chodorow and Dirolf• NoSQL Paper at

http://wiki.hsr.ch/Datenbanken/files/Weber_NoSQL_Paper.pdf

• Why MongoDB is awesome at http://www.slideshare.net/jnunemaker/why-mongodb-is-awesome

• MongoDB wiki at http://en.wikipedia.org/wiki/MongoDB