Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


MongoDB @ Montreal.rb

No description

Olivier Melcher

on 16 February 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of MongoDB @ Montreal.rb

Mongod is the server process:
it waits for a conneciton
it holds one or several databases {name: 'mongo'} Rich query language Availability Scalability Document-oriented Easy to use Fast Well-documented Javascript shell Philosophy {install: 'easy'} Quick Start { url: 'http://try.mongodb.org' } In your browser On your computer { url: 'http://www.mongodb.org/downloads' } What's in the box? {type: 'db'} Data Model {collection: 'documents'} Each database is independent, and the data for each database is stored separately. Mongo is a javascript shell that lets you connect to a mongod. A database holds a set of collections
(Mongo DB ~= SQL DB) TCP connections have the following syntax. A collection holds a set of documents
(Mongo Collection ~= SQL Table) A document is a set of fields
(Mongo Document ~= SQL Record) A field is a key-value pair
(Mongo Field ~= SQL Attribute) A key is a name, a value can be :
a datatype like String, Integer, Float, Timestamp, Binary, BSON ObjectId (12-byte binary), ...
a document
an array of values
(Mongo Field ~= Ruby Hash) { ruby: 'gems' } Pick your gems MongoDB also comes with a Ruby driver ( and also drivers for C, C#, C++, Erlang, Haskell, Java, Javascript, Perl, PHP, Python, and Scala (via Casbah) Devise
Heroku & MongoHQ
Remarkable_mongoid (rspec matchers)
fast-paced development Query Language Sharding Geolocation GridFS Capped collections Cool Stuff { from: 'HUMONGOUS' } { ODMs: ['Mongoid', 'Mongo Mapper'] } Choose your ORM Thank you! { read: 'more' } Write concern Replica Sets MapReduce MongoDB scales horizontally via an auto-sharding architecture: Automatic balancing for changes in load and data distribution
Easy addition of new machines
Scaling out to one thousand nodes
No single points of failure
Automatic failover MongoDB supports asynchronous replication of data between servers for failover and redundancy. It offers automatic failover and recovery of member nodes Only one server (in the set/shard) is active for writes (the primary, or master) at a given time, reads can be served from secondary nodes (eventually consistent)

Supports 1-7 servers in the cluster
Automatic failover and recovery
Data center aware (coming soon)
Supports passive set members (slaves) that are never primary MongoDB supports two-dimensional geospatial indexes. It is designed with location-based queries in mind, such as "find me the closest N items to my location." It can also efficiently filter on additional criteria, such as "find me the closest N museums to my location." { in : 'javascript' } { :in => 'ruby' } BSON objects in MongoDB are limited to 4MB in size. GridFS, which stands for "Grid File Store", is a specification for storing large files in MongoDB. It works by transparently dividing a file into manageable chunks and storing each of those chunks as a separate document. GridFS requires two collections to achieve this: one collection stores each file's metadata (e.g., name, size, etc.) and another stores the chunks themselves. { collection : 'chunks' } { collection : 'files' } Capped collections are fixed-sized collections that have a very high performance auto-FIFO age-out feature (based on insertion order). They maintain insertion order for the objects in the collection; this is useful for logging, caching, or auto-archiving. Map/reduce in MongoDB is useful for background data aggregation operations, with all input coming from a collection and output going to another collection. In sharded environments, data processing of map/reduce operations runs in parallel on all shards. By default, MongoDB doesn't wait for a response when writing to the database. You can make sure operations have succeeded with the getLastError command.

The ruby driver also implements a safe mode : Find an excuse Web applications :
Fast inserts, updates, and queries
Documents map well with OOP and serving data in JSON
Scalability and replication

High performance
Persistent backing of cache High volume problems:
Map Reduce

Archiving and event logging:
Capped collections Documentation
http://www.mongodb.org MongoDB in action by Kyle Banker
http://www.manning.com/banker/ Scaling MongoDB by Kristina Chodorow
http://amzn.to/fNsXma 10Gen Videos
http://www.10gen.com/video Use it ! CREATE DATABASE CREATE TABLE CREATE INDEX INSERT DATA It speaks javascript... {query: 'javascript'} ...and Ruby {driver: 'ruby'} Databases are created on the fly.

Collections are schema-less. MongoDB uses B-tree indexes.
They work as you would expect from an SQL database Indexes work well on SQL databases.
They work well on MongoDB too. MongoDB documents map nicely to OOP

Embeds vs. References

ObjectIDs: 12-byte binaries JAVASCRIPT EVAL & FUNCTIONS UPDATE DATA UPDATE DATA Indexes work well on SQL databases.
They work well on MongoDB too. Conditional operators for dynamic queries

The deeper you embed, the more difficult it is to query.

Denormalizing is ok QUERY DATA QUERY DATA The deeper documents are embedded, the more difficult they are to query Fire and Forget

Atomic operators
upserts for performance What makes MongoDB unique? Install MongoDB The features The Gem Mongo::Connection Mongo::DB Mongo::Collection Mongo::Collection#find Mongo::Collection#insert Mongo::Collection#update Mongo::DB#command
Full transcript