SlideShare a Scribd company logo
base de dados orientada a
documentos para aplicações Web


         Kristina Chodorow
Who am I?

Software Engineer at




           Here from New York City
Why Use
Non-Relational DBs?
Latinoware
Latinoware
CAP
• Consistency
    nome : "joe"         nome : "joe"



• Availability


• Partitioning
Key-Value Stores

    Key            Value
    foo            bar
    x              123
    ts             6:13:26 12/3/1945
    data           x9Fx44x1e


Tokyo Cabinet, Dynamo, MemcacheDB
Key-Value Stores




•Fast     •Too simple
•Simple
Column-Oriented
Cassandra
Document-Oriented
{
    date : Date(2007-05-07),
    time : {
        start : 9.25,
        end : 10.25
    }
    sum : 0,
    comments : ["task 1", "run 4", "testing module"]
}

                       vs.
Consistency
Availability
Partitioning
Consistency
Availability   master

Partitioning



               slave
Consistency
Availability
Partitioning


               slave
Consistency
Availability
Partitioning


               master
Consistency
Availability    slave
Partitioning


               master
Consistency
Availability
Partitioning                       Pair


                          Router

                                          Pair




                                   Pair

...eventual consistency
Latinoware
Latinoware
Introduction to MongoDB
A JavaScript Database

$ mongodb-linux-1.0/bin/mongo
MongoDB shell version: 1.0.0
url: test
connecting to: test
type "help" for help
>
JSON and BSON
Strict JSON types:
{
  x : null, y : true, z : 123, w : "xyz",
  a : { b : 1 }, c : [1, 2, 3]
}

Mongo JSON adds:
{
    ts : new Date(),
    query : /regex/ig,
    _id : new ObjectId()
}
Collections, not Tables
Collections

{
    date : Date(2007-05-07),
    time : {
        start : 9.25,
        end : 10.25
    }
    sum : 0,
    comments : ["task 1", "run 4"]
}
Using the Shell

> db
test
> use xyz
> db
xyz
> db.splorch.find()
>
Inserting

> db.foo.insert({name : "Joe", age : 34})

> db.foo.find({name : "Joe"})
{
    "_id" :
  ObjectId("2fe3e4d892aa73234c910bed"),
    "name" : "Joe",
    "age" : 34
}
Object Ids
            an autogenerated primary key


"_id" : ObjectId("2fe3e4d892aa73234c910bed")


12 bytes:

    2fe3e4d892aa73234c910bed
    |------||----||--||----|
       ts     mac pid inc
Nested Objects

> db.blog.insert({title : "First Post",
    content : "Hello, world!",
    author : {name : "Joe", id : 123},
    comments : []
})
Querying
posts = db.blog.find({
    "author" : "Joe"})

commentsByFred = db.blog.find({
    "comments.author" : "Fred"})

commentedByFred = db.blog.find({
    "comments.author" : /fred/i})
Speaking of indexing…
db.people.ensureIndex({"age" : 1});

db.people.ensureIndex({
    "name" : -1,
    "ts" : -1,
    "comments.author" : 1
});
Updating

db.blog.update({title : "First Post"}, {
  $push : {
    comments : {
      author : "Fred",
      comment : "Dumb post."
    }
  }
});
…which gives us:
> db.blog.findOne()
{
    _id : ObjectId("4ae06192213900000000745c"),
    "title" : "First Post",
    "content" : "Hello, world!"
    "author" : {"name" : "Joe", "id" : 123}
    "comments" : [{
       "author" : "Fred",
       "comment" : "Dumb post"
    }]
}
$ instead of >, <, =, etc.

$gt, $gte, $lt, $lte, $eq, $neq, $exists,
$set, $mod, $where, $in, $nin, $inc
$push, $pull, $pop, $pushAll, $popAll

db.foo.bar.find({x : {$gt : 4}})
$where
db.blog.findOne({$where :
    'this.y == (this.x + this.z)'});

Will work:
{"x" : 1, "y" : 4, "z" : 3}
{"x" : "hi", "y" : "hibye", "z" : "bye"}

Won’t work:
{"x" : 1, "y" : 1}
Optimizing $where
db.blogs.findOne({
    name : "Sally",
    age : {'$gt' : 18},
    $where : 'Array.sort(this.interests)[2]
  == "volleyball"'});
Cursors
cursor = db.blah.find(array("foo" : "bar"))

while (cursor.hasNext()) {
    obj = cursor.next()
}
Applications
soliMAP
           @trackmeet




                                  FetLife

Dextify2
Paging
cursor = db.results.find()
    .sort({"ts" : -1})
    .skip(page_num * results_per_page)
    .limit(results_per_page);
Logging

•   insert/update/remove is fast
•   Capped collections
•   Schemaless
•   $inc for counts
Storing Files
Max: 4Mb
Storing Files




(More than 4 Mb)
Storing Files


J   J   J

                            chunks
J   J   J


J   J   J           _id :   J        files
Storing Files
ObjectId fileId = new ObjectId();

fileObj = {
    _id : fileId,
    filename : "ggbridge.png",
    user : "joe",
    takenIn : "San Francisco"
}

chunkObj = {
    fileId : fileId,
    chunkNum : N
    data : <binary data>
}
Aggregation
group =~ GROUP BY

Map/Reduce
db.runCommand({
    mapreduce : <collection>,
    map : <mapfunction>,
    reduce : <reducefunction>
    [, query : <query filter object>]
    [, out : <outputcollectionname>]
    [, keeptemp: <true|false>]
    [, finalize : <finalizefunction>]
})
www.mongodb.org
Drivers




C#, Erlang, Factor
Thank you!

  kristina@10gen.com
      @kchodorow

        @mongodb
irc.freenode.net#mongodb
     www.mongodb.org

More Related Content

PDF
Indexing
KEY
Introduction to MongoDB
PPT
Introduction to MongoDB
PPTX
Aggregation in MongoDB
PPTX
MongoDB Shell Tips & Tricks
PPT
Introduction to MongoDB
PDF
Getting Started with MongoDB
PDF
Inside MongoDB: the Internals of an Open-Source Database
Indexing
Introduction to MongoDB
Introduction to MongoDB
Aggregation in MongoDB
MongoDB Shell Tips & Tricks
Introduction to MongoDB
Getting Started with MongoDB
Inside MongoDB: the Internals of an Open-Source Database

What's hot (20)

KEY
C# Development (Sam Corder)
PDF
Aggregation Framework MongoDB Days Munich
PPTX
Shell Tips & Tricks
PPTX
Mastering the MongoDB Javascript Shell
PPTX
MongoDB-SESSION03
PPTX
Back to Basics Webinar 5: Introduction to the Aggregation Framework
KEY
Python Development (MongoSF)
PPTX
Aggregation Framework
PDF
MongoDB: Intro & Application for Big Data
PPTX
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
ODP
Python and MongoDB
PPTX
Back to Basics Webinar 2: Your First MongoDB Application
PDF
Realm: Building a mobile database
PPTX
Redis data modeling examples
PDF
はじめてのMongoDB
PPTX
PostgreSQL 9.4 JSON Types and Operators
PPTX
Back to Basics: My First MongoDB Application
PPTX
Mongo db queries
PPTX
Back to Basics, webinar 2: La tua prima applicazione MongoDB
PPTX
Beyond the Basics 2: Aggregation Framework
C# Development (Sam Corder)
Aggregation Framework MongoDB Days Munich
Shell Tips & Tricks
Mastering the MongoDB Javascript Shell
MongoDB-SESSION03
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Python Development (MongoSF)
Aggregation Framework
MongoDB: Intro & Application for Big Data
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Python and MongoDB
Back to Basics Webinar 2: Your First MongoDB Application
Realm: Building a mobile database
Redis data modeling examples
はじめてのMongoDB
PostgreSQL 9.4 JSON Types and Operators
Back to Basics: My First MongoDB Application
Mongo db queries
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Beyond the Basics 2: Aggregation Framework
Ad

Viewers also liked (8)

PDF
San Francisco Java User Group
PPTX
Non-Relational Databases
PPT
Micromedia Powerpoint2
PDF
OSCON 2009 Lightning Talk
PPT
Pohnpei 2009 Closing Slideshow
PPTX
Dropping ACID with MongoDB
PDF
Study: The Future of VR, AR and Self-Driving Cars
PDF
Hype vs. Reality: The AI Explainer
San Francisco Java User Group
Non-Relational Databases
Micromedia Powerpoint2
OSCON 2009 Lightning Talk
Pohnpei 2009 Closing Slideshow
Dropping ACID with MongoDB
Study: The Future of VR, AR and Self-Driving Cars
Hype vs. Reality: The AI Explainer
Ad

Similar to Latinoware (20)

PDF
Building Apps with MongoDB
PPT
9b. Document-Oriented Databases lab
KEY
MongoDB at GUL
KEY
Managing Social Content with MongoDB
KEY
Mongodb intro
PDF
What do you mean, Backwards Compatibility?
PDF
Whats new in mongoDB 2.4 at Copenhagen user group 2013-06-19
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
PDF
MongoDB: Optimising for Performance, Scale & Analytics
KEY
MongoDB, PHP and the cloud - php cloud summit 2011
PDF
DataMapper
PPTX
Einführung in MongoDB
KEY
Mongo db勉強会20110730
KEY
MongoDB at ZPUGDC
PDF
Superficial mongo db
PDF
NoSQL Infrastructure
PDF
10gen Presents Schema Design and Data Modeling
PPTX
Back to Basics Webinar 2 - Your First MongoDB Application
KEY
Schema Design with MongoDB
PDF
MongoDB Aggregation Framework
Building Apps with MongoDB
9b. Document-Oriented Databases lab
MongoDB at GUL
Managing Social Content with MongoDB
Mongodb intro
What do you mean, Backwards Compatibility?
Whats new in mongoDB 2.4 at Copenhagen user group 2013-06-19
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB, PHP and the cloud - php cloud summit 2011
DataMapper
Einführung in MongoDB
Mongo db勉強会20110730
MongoDB at ZPUGDC
Superficial mongo db
NoSQL Infrastructure
10gen Presents Schema Design and Data Modeling
Back to Basics Webinar 2 - Your First MongoDB Application
Schema Design with MongoDB
MongoDB Aggregation Framework

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Modernizing your data center with Dell and AMD
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Advanced Soft Computing BINUS July 2025.pdf
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Modernizing your data center with Dell and AMD
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Latinoware