MongoDB
-
Upload
rony-gregory -
Category
Technology
-
view
2.044 -
download
3
description
Transcript of MongoDB
![Page 1: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/1.jpg)
MongoDB
ByRony Abraham Gregory
Model Engineering College
![Page 2: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/2.jpg)
What is MongoDB? • Humongous (huge + monstrous)• Document Database• Schema free• C++• Open Source
![Page 3: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/4.jpg)
Database Paradigms • Relational (RDBMS)• NoSQLoKey-value storesoDocument databasesoWide column stores (BigTable
and clones)oGraph databases
![Page 5: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/5.jpg)
Relational Databases• ACID (Atomicity Consistency
Isolation and Durability)• SQL• MySQL, PostgreSQL, Oracle, etc.
![Page 6: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/7.jpg)
Key-value stores
Fig: A key-value store
![Page 8: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/9.jpg)
Document databases
Fig: A document database
![Page 10: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/11.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/15.jpg)
Features• Standard database stuff• Indexing• Replication/failover support
![Page 16: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/17.jpg)
Features• Schema-less; very flexible• Auto-sharding (alpha)• Makes for easy horizontal;
scaling• Map/Reduce
![Page 18: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/18.jpg)
Features• Very, very fast• Super easy to install• Strong with major languages
![Page 19: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/19.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/20.jpg)
Features: Official Drivers• .NET, Java, JavaScript, Ruby,
Node.js, PHP, Haskell, C/C++, Perl
![Page 21: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/22.jpg)
Concepts: Document-Oriented
![Page 23: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/23.jpg)
Concepts: Document-Oriented
Concept Mapping
![Page 24: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/24.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/25.jpg)
Concepts: Cursors• The find() function returns a
cursor object
![Page 26: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/26.jpg)
Basic Operations• Insert• Find• Update• Remove• ensureIndex
![Page 27: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/27.jpg)
Basic Operations• Insertdb.test.insert({hello:’world’});• FindoEquivalent of Select * FROM
test;
![Page 28: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/28.jpg)
Basic Operations:Updatedb.test.update(<condition>,<operation>)
![Page 29: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/29.jpg)
Basic Operations: Removedb.test.remove(<condition>)
![Page 30: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/30.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/31.jpg)
MongoDB in action!
![Page 32: MongoDB](https://reader036.fdocuments.in/reader036/viewer/2022070315/554f9115b4c905d25b8b51e6/html5/thumbnails/32.jpg)
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