0
Wojciech Sznapka<br />13.05.2011<br />MongoDB – document oriented databaseDoes NoSQL make sense?<br />
Agenda<br />NoSQL – definition and solutions,<br />MongoDB – description and feautres,<br />MongoDB usage,<br />Who uses i...
NoSQL<br />It’s a class of database management systems, the alternative for relational databases (RDBM). Sometimes people ...
NoSQL solutions<br />Document oriented:<br />MongoDB<br />Apache CouchDB<br />Key Value storage:<br />Big Table (Google Ap...
MongoDB<br />Document Oriented – stores JSON documetns ,<br />Very efficient (written in C++),<br />High scallable,<br />S...
MongoDB features<br />Stores dynamic JSON documents (internally represented as BSON – Binary JSON),<br />Full support for ...
Where it applies?<br />Web appliactions (logging, caching, processing huge amount of data),<br />High load / high scalabil...
Who uses it?<br />
MongoDB vs. SQL<br />
Schema-free – no migrations!<br />MongoDB (as every NoSQL solution) is schema-free, so if we need to put new field into ex...
Examples<br />Document,<br />Aggregated document,<br />Sorting, limiting,<br />Advanced  searching (including regexp),<br ...
CRUD on Documents<br />> db.foo.insert({name: "Wojciech", age: 25, tags: ["male", "developer"]})<br />> db.foo.insert({nam...
Aggregated documents<br />> db.logs.insert({msg: "error occured", details: {line: 2, severity: 3}})<br />> db.logs.insert(...
Sorting and limiting<br />> db.foo.find({}, {name: 1}).sort({name: -1})<br />{ "_id" : ObjectId("4dcd13647ffde8d258900f7a"...
Sorting and limiting<br />> db.foo.find({}, {name: 1}).sort({name: -1})<br />{ "_id" : ObjectId("4dcd13647ffde8d258900f7a"...
Advanced queries<br />>  db.foo.find({tags: "developer", age: {$exists: true}})<br />{ "_id" : ObjectId("4dcd13647ffde8d25...
PHP example<br /><?php<br />$mongo = new Mongo();<br />$db = $mongo->foo;<br />$collection = $db->foo;<br />$wojtek = arra...
Does NoSQL make sense?<br />Yes, if we will use NoSQL databases along with SQL, if they are needed. Dropping SQL databases...
Thank you for an attention<br />Any questions<br />?<br />
Upcoming SlideShare
Loading in...5
×

Mongo db – document oriented database

4,091

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,091
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
24
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Mongo db – document oriented database"

  1. 1. Wojciech Sznapka<br />13.05.2011<br />MongoDB – document oriented databaseDoes NoSQL make sense?<br />
  2. 2. Agenda<br />NoSQL – definition and solutions,<br />MongoDB – description and feautres,<br />MongoDB usage,<br />Who uses it?<br />Schema-free,<br />Some live examples,<br />Does NoSQL make sense?<br />
  3. 3. NoSQL<br />It’s a class of database management systems, the alternative for relational databases (RDBM). Sometimes people call they „next generation databases”,<br />NoSQL databases haven’t got schema like relational systems, there’s no table joining and have good scalling facilities.<br />
  4. 4. NoSQL solutions<br />Document oriented:<br />MongoDB<br />Apache CouchDB<br />Key Value storage:<br />Big Table (Google App Engine)<br />Dynamo (Amazon Web Services)<br />Apache Cassandra (Facebook)<br />Project Voldemort (LinkedIn)<br />
  5. 5. MongoDB<br />Document Oriented – stores JSON documetns ,<br />Very efficient (written in C++),<br />High scallable,<br />Schema-free – high flexibility,<br />Supports many software platform and has plenty programming language drivers (PHP, .NET, Java, Python, Ruby, etc.),<br />Developping since August 2007, first release in 2009,<br />Open Source (GNU AGPL).<br />
  6. 6. MongoDB features<br />Stores dynamic JSON documents (internally represented as BSON – Binary JSON),<br />Full support for indicies,<br />Replication and high availability,<br />Complex queries (which are also represented as JSONs),<br />Map/Reduce mechanism – handy way of aggregation and processing data (combination of SQL’s Group By and stored procedures),<br />GridFS – mongo’s file system, which allows to store files in database.<br />
  7. 7. Where it applies?<br />Web appliactions (logging, caching, processing huge amount of data),<br />High load / high scalabillity,<br />GIS solutions (it supports 2d geospatial indicies – longitude/latitude)<br />Where it shouldn’t be used?<br />High transactional operations (no support for ACID principle),<br />Cases which needs SQL (many joins for example)<br />
  8. 8. Who uses it?<br />
  9. 9. MongoDB vs. SQL<br />
  10. 10. Schema-free – no migrations!<br />MongoDB (as every NoSQL solution) is schema-free, so if we need to put new field into existing document, we don’t need to do extra things, like Alter Table in SQL database. We just start using document with new field,<br />It means, that we don’t need to care about an migrations – it’s done transparently.<br />
  11. 11. Examples<br />Document,<br />Aggregated document,<br />Sorting, limiting,<br />Advanced searching (including regexp),<br />PHP code.<br />
  12. 12. CRUD on Documents<br />> db.foo.insert({name: "Wojciech", age: 25, tags: ["male", "developer"]})<br />> db.foo.insert({name: "Andreea", tags: ["female", "rt master"]})<br />> db.foo.insert({name: "Okky", tags: ["male", "developer"]})<br />> db.foo.update({name: "Wojciech"}, {$set: {surname: "Sznapka"}})<br />> db.foo.remove({name: "Okky"});<br />> db.foo.find()<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea", "tags" : [ "female", "rt master" ] }<br />{ "_id" : ObjectId("4dcd13ce7ffde8d258900f7c"), "name" : "Okky", "tags" : [ "male", "developer" ] }<br />{ "_id" : ObjectId("4dcd13647ffde8d258900f7a"), "age" : 25, "name" : "Wojciech", "surname" : "Sznapka", "tags" : [ "male", "developer" ] }<br />> db.foo.find({tags: "rt master"})<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea", "tags" : [ "female", "rt master" ] }<br />
  13. 13. Aggregated documents<br />> db.logs.insert({msg: "error occured", details: {line: 2, severity: 3}})<br />> db.logs.insert({msg: "user logged in", details: {severity: 10}})<br />> db.logs.find({'details.severity': 10})<br />{ "_id" : ObjectId("4dcd15d77ffde8d258900f7e"), "msg" : "user logged in", "details" : { "severity" : 10 } }<br />
  14. 14. Sorting and limiting<br />> db.foo.find({}, {name: 1}).sort({name: -1})<br />{ "_id" : ObjectId("4dcd13647ffde8d258900f7a"), "name" : "Wojciech" }<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea" }<br />> db.foo.find().limit(1)<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea", "tags" : [ "female", "rt master" ] }<br />
  15. 15. Sorting and limiting<br />> db.foo.find({}, {name: 1}).sort({name: -1})<br />{ "_id" : ObjectId("4dcd13647ffde8d258900f7a"), "name" : "Wojciech" }<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea" }<br />> db.foo.find().limit(1)<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea", "tags" : [ "female", "rt master" ] }<br />
  16. 16. Advanced queries<br />> db.foo.find({tags: "developer", age: {$exists: true}})<br />{ "_id" : ObjectId("4dcd13647ffde8d258900f7a"), "age" : 25, "name" : "Wojciech", "surname" : "Sznapka", "tags" : [ "male", "developer" ] }<br />> db.foo.find({name: /a$/}, {name: 1})<br />{ "_id" : ObjectId("4dcd13b37ffde8d258900f7b"), "name" : "Andreea" }<br />{ "_id" : ObjectId("4dcd17ae7ffde8d258900f80"), "name" : "Tamara" }<br />
  17. 17. PHP example<br /><?php<br />$mongo = new Mongo();<br />$db = $mongo->foo;<br />$collection = $db->foo;<br />$wojtek = array("name" => "Wojciech", "tags" => array("male", "developer"), "age" => 25);<br />$okky = array("name" => "Okky", "tags" => array("male", "developer"));<br />$collection->insert($wojtek);<br />$collection->insert($okky);<br />$cursor = $collection->find();<br />foreach ($cursor as $document) {<br /> printf("Name: %sn", $document["name"]);<br />}<br />
  18. 18. Does NoSQL make sense?<br />Yes, if we will use NoSQL databases along with SQL, if they are needed. Dropping SQL databases completly isn’t the best idea for huge and complicated applications, but supplementing data model with NoSQL database (like MongoDB), can improve application performance and shorten development process,<br />It should be rather „Not onyl SQL”.<br />
  19. 19. Thank you for an attention<br />Any questions<br />?<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×