Mongo db – document oriented database
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Mongo db – document oriented database

on

  • 3,303 views

 

Statistics

Views

Total Views
3,303
Views on SlideShare
2,183
Embed Views
1,120

Actions

Likes
2
Downloads
16
Comments
0

3 Embeds 1,120

http://blog.sznapka.pl 1116
http://sznapi.kwiatkowski.xsdev.pl 3
http://www.pinterest.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mongo db – document oriented database Presentation Transcript

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