MongoDB

 By
      Rony Abraham Gregory
       Model Engineering College
What is MongoDB?
•   Humongous (huge + monstrous)
•   Document Database
•   Schema free
•   C++
•   Open Source
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!
Database Paradigms
• Relational (RDBMS)
• NoSQL
  oKey-value stores
  oDocument databases
  oWide column stores (BigTable and
    clones)
  oGraph databases
Relational Databases
• ACID (Atomicity Consistency Isolation
  and Durability)
• SQL
• MySQL, PostgreSQL, Oracle, etc.
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.
Key-value stores




       Fig: A key-value store
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, e
  tc.
Document databases




     Fig: A document database
Why NoSQL?
• Schema-free
• Massive data stores
• Scalability
• Some services simpler to implement
  than using RDBMS
• Great fit for many Web 2.0 applications
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”
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
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
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
Features
• Standard database stuff
   • Indexing
   • Replication/failover support
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
Features
•   Schema-less; very flexible
•   Auto-sharding (alpha)
•   Makes for easy horizontal; scaling
•   Map/Reduce
Features
• Very, very fast
• Super easy to install
• Strong with major languages
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)
Features: Official Drivers
• .NET, Java, JavaScript, Ruby, Node.js, PH
  P, Haskell, C/C++, Perl
Concepts: Document-Oriented
• Think of “documents” as
  objects/database records
• Documents are basically just JSON in
  binary
• Ability to store information all together
Concepts: Document-Oriented
Concepts: Document-Oriented
      Concept Mapping
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
Concepts: Cursors
• The find() function returns a cursor
  object
Basic Operations
•   Insert
•   Find
•   Update
•   Remove
•   ensureIndex
Basic Operations
• Insert
db.test.insert({hello:’world’});
• Find
   oEquivalent of Select * FROM test;
Basic Operations:Update
db.test.update(<condition>,<operation>)
Basic Operations: Remove
db.test.remove(<condition>)
Basic Operations: Indexing
• Its usually a good idea to index
  collections
• How and which columns depend on
  what is to be done
db.test.ensureIndex({hello:I})
MongoDB in action!
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

MongoDB