SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Introduction

Christian Kvalheim - christkv@10gen.com
                @christkv
Today's Talk
• Quick introduction to NoSQL

• Some Background about mongoDB

• Using mongoDB

• Deploying mongoDB
Database Landscape

                               memcached
                                    key/value
   scalability & performance




                                                                RDBMS




                                       depth of functionality
What is NoSQL?




Key / Value   Column   Graph   Document
Key-Value Stores
• A mapping from a key to a value
• The store doesn't know anything about the the key
  or value
• The store doesn't know anything about the insides
  of the value
• Operations
 • Set, get, or delete a key-value pair
Column-Oriented Stores
• Like a relational store, but flipped around: all data
 for a column is kept together
• An index provides a means to get a column value for a
  record
• Operations:
• Get, insert, delete records; updating fields
• Streaming column data in and out of Hadoop
Graph Databases
• Stores vertex-to-vertex edges
• Operations:
 • Getting and setting edges
 • Sometimes possible to annotate vertices or edges
• Query languages support finding paths between
  vertices, subject to various constraints
Document Stores
• The store is a container for documents
• Documents are made up of named fields
 • Fields may or may not have type definitions
 • e.g. XSDs for XML stores, vs. schema-less JSON stores
• Can create "secondary indexes"
• These provide the ability to query on any document field(s)
• Operations:
• Insert and delete documents
• Update fields within documents
What is mongoDB?
MongoDB is a scalable, high-performance,
open source NoSQL database.

• Document-oriented storage
• Full Index Support
• Replication & High Availability
• Auto-Sharding
• Querying
• Fast In-Place Updates
• Map/Reduce
• GridFS
• Company behind mongoDB
 – (A)GPL license, own copyrights, engineering team
 – support, consulting, commercial license

• Management
 – Google/DoubleClick, Oracle, Apple, NetApp
 – Funding: Sequoia, Union Square, Flybridge
 – Offices in NYC, Palo Alto, London, Dublin
 – 100+ employees
Where can you use it?
MongoDB is Implemented in C++
• Platforms 32/64 bit Windows, Linux, Mac OS-X,
  FreeBSD, Solaris

Drivers are available in many languages

10gen supported
• C, C# (.Net), C++, Erlang, Haskell, Java, JavaScript,
  Perl, PHP, Python, Ruby, Scala, Node.JS

Community supported
• Clojure, ColdFusion, F#, Go, Groovy, Lua, R ...
  http://www.mongodb.org/display/DOCS/Drivers
History
• First release – February 2009
• v1.0 - August 2009
• v1.2 - December 2009 – MapReduce, ++
• v1.4 - March 2010 – Concurrency, Geo
• V1.6 - August 2010 – Sharding, Replica Sets
• V1.8 – March 2011 – Journaling, Geosphere
• V2.0 - Sep 2011 – V1 Indexes, Concurrency
• V2.2 - Soon - Aggregation, Concurrency
Terminology
RDBMS           MongoDB
Table           Collection
Row(s)          JSON Document
Index           Index
Join            Embedding & Linking
Partition       Shard
Partition Key   Shard Key
Documents
  Blog Post Document

> p = { author: "Chris",
         date: new ISODate(),
         text: "About MongoDB...",
         tags: ["tech", "databases"]}

> db.posts.save(p)
Querying

> db.posts.find()

   { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
     author : "Chris",
     date : ISODate("2012-02-02T11:52:27.442Z"),
     text : "About MongoDB...",
     tags : [ "tech", "databases" ] }

Notes:
     _id is unique, but can be anything you'd like
Introducing BSON
JSON has powerful, but limited set of datatypes
 • arrays, objects, strings, numbers and null

BSON is a binary representation of JSON
 • Adds extra dataypes with Date, Int types, Id, …
 • Optimized for performance and navigational abilities
 • And compression

MongoDB sends and stores data in BSON
 • bsonspec.org
Secondary Indexes
Create index on any Field in Document

//   1 means ascending, -1 means descending
 > db.posts.ensureIndex({author: 1})

> db.posts.findOne({author: 'Chris'})

  { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
    author: "Chris", ... }
Compound Indexes
Create index on multiple fields in a Document

//   1 means ascending, -1 means descending
 > db.posts.ensureIndex({author: 1, ts: -1})

> db.posts.find({author: 'Chris'}).sort({ts: -1})

  [{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
     author: "Chris", ...},
   { _id : ObjectId("4f61d325c496820ceba84124"),
     author: "Chris", ...}]
Query Operators
Conditional Operators
- $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type
- $lt, $lte, $gt, $gte

// find posts with any tags
> db.posts.find({tags: {$exists: true }})

// find posts matching a regular expression
> db.posts.find({author: /^ro*/i })

// count posts by author
> db.posts.find({author: 'Chris'}).count()
Examine the query plan
> db.posts.find({"author": 'Ross'}).explain()
{
	    "cursor" : "BtreeCursor author_1",
	    "nscanned" : 1,
	    "nscannedObjects" : 1,
	    "n" : 1,
	    "millis" : 0,
	    "indexBounds" : {
	    	   "author" : [
	    	   	    [
	    	   	    	   "Chris",
	    	   	    	   "Chris"
	    	   	    ]
	    	   ]
	    }
}
Atomic Operations
  $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $bit

// Create a comment
> new_comment = { author: "Fred",
                      date: new Date(),
                      text: "Best Post Ever!"}

// Add to post
> db.posts.update({ _id: "..." },
  	     	   	     {"$push": {comments: new_comment},
                   "$inc": {comments_count: 1}
                  });
Nested Documents
    {       _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
            author : "Chris",
            date : "Thu Feb 02 2012 11:50:01",
            text : "About MongoDB...",
            tags : [ "tech", "databases" ],
            comments : [{
	           	   author : "Fred",
	           	   date : "Fri Feb 03 2012 13:23:11",
	           	   text : "Best Post Ever!"
	           }],
            comment_count : 1
        }
Nested Documents
    {       _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
            author : "Chris",
            date : "Thu Feb 02 2012 11:50:01",
            text : "About MongoDB...",
            tags : [ "tech", "databases" ],
            comments : [{
	           	   author : "Fred",
	           	   date : "Fri Feb 03 2012 13:23:11",
	           	   text : "Best Post Ever!"
	           }],
            comment_count : 1
        }
Secondary Indexes
// Index nested documents
> db.posts.ensureIndex("comments.author": 1)
> db.posts.find({"comments.author": "Fred"})

// Index on tags (multi-key index)
> db.posts.ensureIndex( tags: 1)
> db.posts.find( { tags: "tech" } )
Geo
  • Geo-spatial queries
   • Require a geo index
   • Find points near a given point
   • Find points within a polygon/sphere


// geospatial index
> db.posts.ensureIndex( "author.location": "2d" )
> db.posts.find( "author.location" :
                 { $near : [22, 42] } )
Map Reduce
    The caller provides map and reduce functions written
    in JavaScript
// Emit each tag
> map = "this['tags'].forEach(
    function(item) {emit(item, 1);}
  );"

// Calculate totals
> reduce = "function(key, values) {
     var total = 0;
     var valuesSize = values.length;
     for (var i=0; i < valuesSize; i++) {
       total += parseInt(values[i], 10);
     }
     return total;
  };
Map Reduce
// run the map reduce
> db.posts.mapReduce(map, reduce, {"out": { inline : 1}});
{
	    "results" : [
	    	    {"_id" : "databases", "value" : 1},
	    	    {"_id" : "tech", "value" : 1 }
	    ],
	    "timeMillis" : 1,
	    "counts" : {
	    	    "input" : 1,
	    	    "emit" : 2,
	    	    "reduce" : 0,
	    	    "output" : 2
	    },
	    "ok" : 1,
}
Aggregation - coming in 2.2
// Count tags
> agg = db.posts.aggregate(
    {$unwind: "$tags"},
    {$group : {_id : "$tags",
               count : {$sum: 1}}}
  )

> agg.result
  [{"_id": "databases", "count": 1},
   {"_id": "tech", "count": 1}]
GridFS
 Save files in mongoDB
 Stream data back to the client

// (Python) Create a new instance of GridFS
>>> fs = gridfs.GridFS(db)

// Save file to mongo
>>> my_image = open('my_image.jpg', 'r')
>>> file_id = fs.put(my_image)

// Read file
>>> fs.get(file_id).read()
Rich Documents

• Intuitive
• Developer friendly
• Encapsulates whole objects
• Performant
• They are scalable
Rich Documents
{   _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
    line_items : [ { sku: 'tt-123',
                     name: 'Coltrane: Impressions' },
                   { ski: 'tt-457',
                     name: 'Davis: Kind of Blue' } ],
    address : { name: 'Banker',
                street: '111 Main',
                zip: 10010 },
    payment: { cc: 4567,
               exp: Date(2012, 7, 7) },
    subtotal: 2355
}
Deployment

• Single server
 - need a strong backup plan   P
Deployment

• Single server
 - need a strong backup plan       P
• Replica sets
 - High availability           P   S   S
 - Automatic failover
Deployment

• Single server
 - need a strong backup plan       P
• Replica sets
 - High availability           P   S   S
 - Automatic failover

• Sharded
 - Horizontally scale
 - Auto balancing              P   S   S

                               P   S   S
MongoDB Use Cases
• Archiving
• Content Management
• Ecommerce
• Finance
• Gaming
• Government
• Metadata Storage
• News & Media
• Online Advertising
• Online Collaboration
• Real-time stats/analytics
• Social Networks
• Telecommunications
In Production
download at mongodb.org

     conferences, appearances, and meetups
                http://www.10gen.com/events



   Facebook             |    Twitter   |        LinkedIn
http://bit.ly/mongofb       @mongodb   http://linkd.in/joinmongo


  support, training, and this talk brought to you by

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
Mongo db report
Mongo db reportMongo db report
Mongo db report
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mango Database - Web Development
Mango Database - Web DevelopmentMango Database - Web Development
Mango Database - Web Development
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongodb tutorial at Easylearning Guru
Mongodb tutorial  at Easylearning GuruMongodb tutorial  at Easylearning Guru
Mongodb tutorial at Easylearning Guru
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 

Andere mochten auch

Intro to NoSQL and MongoDB
 Intro to NoSQL and MongoDB Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDBMongoDB
 
Mastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript ShellMastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript ShellScott Hernandez
 
Seth Edwards on MongoDB
Seth Edwards on MongoDBSeth Edwards on MongoDB
Seth Edwards on MongoDBSkills Matter
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBSean Laurent
 
mongodb-brief-intro-february-2012
mongodb-brief-intro-february-2012mongodb-brief-intro-february-2012
mongodb-brief-intro-february-2012Chris Westin
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBKnoldus Inc.
 
Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDBPankaj Bajaj
 
An Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and KeynoteAn Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and KeynoteMongoDB
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)MongoSF
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 HoursMongoSF
 
Text databases and information retrieval
Text databases and information retrievalText databases and information retrieval
Text databases and information retrievalunyil96
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsJAX London
 
MongoDB 3.2 Feature Preview
MongoDB 3.2 Feature PreviewMongoDB 3.2 Feature Preview
MongoDB 3.2 Feature PreviewNorberto Leite
 

Andere mochten auch (20)

MongoDB Devops Madrid February 2012
MongoDB Devops Madrid February 2012MongoDB Devops Madrid February 2012
MongoDB Devops Madrid February 2012
 
Intro to NoSQL and MongoDB
 Intro to NoSQL and MongoDB Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDB
 
Mastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript ShellMastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript Shell
 
Seth Edwards on MongoDB
Seth Edwards on MongoDBSeth Edwards on MongoDB
Seth Edwards on MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
mongodb-brief-intro-february-2012
mongodb-brief-intro-february-2012mongodb-brief-intro-february-2012
mongodb-brief-intro-february-2012
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDB
 
An Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and KeynoteAn Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and Keynote
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
MongoDB 3.0
MongoDB 3.0 MongoDB 3.0
MongoDB 3.0
 
Plan de entrenamiento Maratón de Madrid Mes 3
Plan de entrenamiento Maratón de Madrid Mes 3Plan de entrenamiento Maratón de Madrid Mes 3
Plan de entrenamiento Maratón de Madrid Mes 3
 
Mongo db intro new
Mongo db intro newMongo db intro new
Mongo db intro new
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 Hours
 
Text databases and information retrieval
Text databases and information retrievalText databases and information retrieval
Text databases and information retrieval
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdams
 
MongoDB 3.2 Feature Preview
MongoDB 3.2 Feature PreviewMongoDB 3.2 Feature Preview
MongoDB 3.2 Feature Preview
 
Mongodb
MongodbMongodb
Mongodb
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB
MongoDBMongoDB
MongoDB
 

Ähnlich wie Mongodb intro

OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyNETWAYS
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDBDoThinger
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRailsMike Dirolf
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCupWebGeek Philippines
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael Bright
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and PythonMike Bright
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC PythonMike Dirolf
 
Schema design
Schema designSchema design
Schema designchristkv
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewAntonio Pintus
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBMongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009Mike Dirolf
 

Ähnlich wie Mongodb intro (20)

OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC Python
 
Schema design
Schema designSchema design
Schema design
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDB
 
MongoDB at RuPy
MongoDB at RuPyMongoDB at RuPy
MongoDB at RuPy
 
MongoDB
MongoDBMongoDB
MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
 

Mehr von christkv

From SQL to MongoDB
From SQL to MongoDBFrom SQL to MongoDB
From SQL to MongoDBchristkv
 
New in MongoDB 2.6
New in MongoDB 2.6New in MongoDB 2.6
New in MongoDB 2.6christkv
 
Lessons from 4 years of driver develoment
Lessons from 4 years of driver develomentLessons from 4 years of driver develoment
Lessons from 4 years of driver develomentchristkv
 
Storage talk
Storage talkStorage talk
Storage talkchristkv
 
Mongo db ecommerce
Mongo db ecommerceMongo db ecommerce
Mongo db ecommercechristkv
 
Cdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupCdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupchristkv
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriverchristkv
 
Node.js and ruby
Node.js and rubyNode.js and ruby
Node.js and rubychristkv
 

Mehr von christkv (8)

From SQL to MongoDB
From SQL to MongoDBFrom SQL to MongoDB
From SQL to MongoDB
 
New in MongoDB 2.6
New in MongoDB 2.6New in MongoDB 2.6
New in MongoDB 2.6
 
Lessons from 4 years of driver develoment
Lessons from 4 years of driver develomentLessons from 4 years of driver develoment
Lessons from 4 years of driver develoment
 
Storage talk
Storage talkStorage talk
Storage talk
 
Mongo db ecommerce
Mongo db ecommerceMongo db ecommerce
Mongo db ecommerce
 
Cdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupCdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetup
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
 
Node.js and ruby
Node.js and rubyNode.js and ruby
Node.js and ruby
 

Kürzlich hochgeladen

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Mongodb intro

  • 1. Introduction Christian Kvalheim - christkv@10gen.com @christkv
  • 2. Today's Talk • Quick introduction to NoSQL • Some Background about mongoDB • Using mongoDB • Deploying mongoDB
  • 3. Database Landscape memcached key/value scalability & performance RDBMS depth of functionality
  • 4. What is NoSQL? Key / Value Column Graph Document
  • 5. Key-Value Stores • A mapping from a key to a value • The store doesn't know anything about the the key or value • The store doesn't know anything about the insides of the value • Operations • Set, get, or delete a key-value pair
  • 6. Column-Oriented Stores • Like a relational store, but flipped around: all data for a column is kept together • An index provides a means to get a column value for a record • Operations: • Get, insert, delete records; updating fields • Streaming column data in and out of Hadoop
  • 7. Graph Databases • Stores vertex-to-vertex edges • Operations: • Getting and setting edges • Sometimes possible to annotate vertices or edges • Query languages support finding paths between vertices, subject to various constraints
  • 8. Document Stores • The store is a container for documents • Documents are made up of named fields • Fields may or may not have type definitions • e.g. XSDs for XML stores, vs. schema-less JSON stores • Can create "secondary indexes" • These provide the ability to query on any document field(s) • Operations: • Insert and delete documents • Update fields within documents
  • 9. What is mongoDB? MongoDB is a scalable, high-performance, open source NoSQL database. • Document-oriented storage • Full Index Support • Replication & High Availability • Auto-Sharding • Querying • Fast In-Place Updates • Map/Reduce • GridFS
  • 10. • Company behind mongoDB – (A)GPL license, own copyrights, engineering team – support, consulting, commercial license • Management – Google/DoubleClick, Oracle, Apple, NetApp – Funding: Sequoia, Union Square, Flybridge – Offices in NYC, Palo Alto, London, Dublin – 100+ employees
  • 11. Where can you use it? MongoDB is Implemented in C++ • Platforms 32/64 bit Windows, Linux, Mac OS-X, FreeBSD, Solaris Drivers are available in many languages 10gen supported • C, C# (.Net), C++, Erlang, Haskell, Java, JavaScript, Perl, PHP, Python, Ruby, Scala, Node.JS Community supported • Clojure, ColdFusion, F#, Go, Groovy, Lua, R ... http://www.mongodb.org/display/DOCS/Drivers
  • 12. History • First release – February 2009 • v1.0 - August 2009 • v1.2 - December 2009 – MapReduce, ++ • v1.4 - March 2010 – Concurrency, Geo • V1.6 - August 2010 – Sharding, Replica Sets • V1.8 – March 2011 – Journaling, Geosphere • V2.0 - Sep 2011 – V1 Indexes, Concurrency • V2.2 - Soon - Aggregation, Concurrency
  • 13. Terminology RDBMS MongoDB Table Collection Row(s) JSON Document Index Index Join Embedding & Linking Partition Shard Partition Key Shard Key
  • 14. Documents Blog Post Document > p = { author: "Chris", date: new ISODate(), text: "About MongoDB...", tags: ["tech", "databases"]} > db.posts.save(p)
  • 15. Querying > db.posts.find() { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "Chris", date : ISODate("2012-02-02T11:52:27.442Z"), text : "About MongoDB...", tags : [ "tech", "databases" ] } Notes: _id is unique, but can be anything you'd like
  • 16. Introducing BSON JSON has powerful, but limited set of datatypes • arrays, objects, strings, numbers and null BSON is a binary representation of JSON • Adds extra dataypes with Date, Int types, Id, … • Optimized for performance and navigational abilities • And compression MongoDB sends and stores data in BSON • bsonspec.org
  • 17. Secondary Indexes Create index on any Field in Document // 1 means ascending, -1 means descending > db.posts.ensureIndex({author: 1}) > db.posts.findOne({author: 'Chris'}) { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author: "Chris", ... }
  • 18. Compound Indexes Create index on multiple fields in a Document // 1 means ascending, -1 means descending > db.posts.ensureIndex({author: 1, ts: -1}) > db.posts.find({author: 'Chris'}).sort({ts: -1}) [{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author: "Chris", ...}, { _id : ObjectId("4f61d325c496820ceba84124"), author: "Chris", ...}]
  • 19. Query Operators Conditional Operators - $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type - $lt, $lte, $gt, $gte // find posts with any tags > db.posts.find({tags: {$exists: true }}) // find posts matching a regular expression > db.posts.find({author: /^ro*/i }) // count posts by author > db.posts.find({author: 'Chris'}).count()
  • 20. Examine the query plan > db.posts.find({"author": 'Ross'}).explain() { "cursor" : "BtreeCursor author_1", "nscanned" : 1, "nscannedObjects" : 1, "n" : 1, "millis" : 0, "indexBounds" : { "author" : [ [ "Chris", "Chris" ] ] } }
  • 21. Atomic Operations $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $bit // Create a comment > new_comment = { author: "Fred", date: new Date(), text: "Best Post Ever!"} // Add to post > db.posts.update({ _id: "..." }, {"$push": {comments: new_comment}, "$inc": {comments_count: 1} });
  • 22. Nested Documents { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "Chris", date : "Thu Feb 02 2012 11:50:01", text : "About MongoDB...", tags : [ "tech", "databases" ], comments : [{ author : "Fred", date : "Fri Feb 03 2012 13:23:11", text : "Best Post Ever!" }], comment_count : 1 }
  • 23. Nested Documents { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "Chris", date : "Thu Feb 02 2012 11:50:01", text : "About MongoDB...", tags : [ "tech", "databases" ], comments : [{ author : "Fred", date : "Fri Feb 03 2012 13:23:11", text : "Best Post Ever!" }], comment_count : 1 }
  • 24. Secondary Indexes // Index nested documents > db.posts.ensureIndex("comments.author": 1) > db.posts.find({"comments.author": "Fred"}) // Index on tags (multi-key index) > db.posts.ensureIndex( tags: 1) > db.posts.find( { tags: "tech" } )
  • 25. Geo • Geo-spatial queries • Require a geo index • Find points near a given point • Find points within a polygon/sphere // geospatial index > db.posts.ensureIndex( "author.location": "2d" ) > db.posts.find( "author.location" : { $near : [22, 42] } )
  • 26. Map Reduce The caller provides map and reduce functions written in JavaScript // Emit each tag > map = "this['tags'].forEach( function(item) {emit(item, 1);} );" // Calculate totals > reduce = "function(key, values) { var total = 0; var valuesSize = values.length; for (var i=0; i < valuesSize; i++) { total += parseInt(values[i], 10); } return total; };
  • 27. Map Reduce // run the map reduce > db.posts.mapReduce(map, reduce, {"out": { inline : 1}}); { "results" : [ {"_id" : "databases", "value" : 1}, {"_id" : "tech", "value" : 1 } ], "timeMillis" : 1, "counts" : { "input" : 1, "emit" : 2, "reduce" : 0, "output" : 2 }, "ok" : 1, }
  • 28. Aggregation - coming in 2.2 // Count tags > agg = db.posts.aggregate( {$unwind: "$tags"}, {$group : {_id : "$tags", count : {$sum: 1}}} ) > agg.result [{"_id": "databases", "count": 1}, {"_id": "tech", "count": 1}]
  • 29. GridFS Save files in mongoDB Stream data back to the client // (Python) Create a new instance of GridFS >>> fs = gridfs.GridFS(db) // Save file to mongo >>> my_image = open('my_image.jpg', 'r') >>> file_id = fs.put(my_image) // Read file >>> fs.get(file_id).read()
  • 30. Rich Documents • Intuitive • Developer friendly • Encapsulates whole objects • Performant • They are scalable
  • 31. Rich Documents { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), line_items : [ { sku: 'tt-123', name: 'Coltrane: Impressions' }, { ski: 'tt-457', name: 'Davis: Kind of Blue' } ], address : { name: 'Banker', street: '111 Main', zip: 10010 }, payment: { cc: 4567, exp: Date(2012, 7, 7) }, subtotal: 2355 }
  • 32. Deployment • Single server - need a strong backup plan P
  • 33. Deployment • Single server - need a strong backup plan P • Replica sets - High availability P S S - Automatic failover
  • 34. Deployment • Single server - need a strong backup plan P • Replica sets - High availability P S S - Automatic failover • Sharded - Horizontally scale - Auto balancing P S S P S S
  • 35. MongoDB Use Cases • Archiving • Content Management • Ecommerce • Finance • Gaming • Government • Metadata Storage • News & Media • Online Advertising • Online Collaboration • Real-time stats/analytics • Social Networks • Telecommunications
  • 37. download at mongodb.org conferences, appearances, and meetups http://www.10gen.com/events Facebook | Twitter | LinkedIn http://bit.ly/mongofb @mongodb http://linkd.in/joinmongo support, training, and this talk brought to you by

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. * memcache, redis, membase\n* mongodb, couch\n* cassandra, riak\n* neo4j, flockdb\n\n
  5. \n
  6. \n
  7. \n
  8. \n
  9. * JSON-style documents with dynamic schemas offer simplicity and power.\n* Index on any attribute, just like you&apos;re used to.\n* Mirror across LANs and WANs for scale and peace of mind.\n* Scale horizontally without compromising functionality.\n* Rich, document-based queries.\n* Atomic modifiers for contention-free performance.\n* Flexible aggregation and data processing.\n* Store files of any size without complicating your stack.\n
  10. \n
  11. \n
  12. \n
  13. * No joins for scalability - Doing joins across shards in SQL highly inefficient and difficult to perform.\n* MongoDB is geared for easy scaling - going from a single node to a distributed cluster is easy.\n* Little or no application code changes are needed to scale from a single node to a sharded cluster.\n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. * If document is always presented as a whole - a single doc gives performance benefits\n* A single doc is not a panacea - as we&apos;ll see\n
  30. * Summarise using mongodb\n
  31. \n
  32. * Single Master..\n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n