• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to MongoDB
 

Introduction to MongoDB

on

  • 1,251 views

An introduction to MongoDB as shown at the Madison MongoDB User Group (MadMUG) meetup on 4/16/2012.

An introduction to MongoDB as shown at the Madison MongoDB User Group (MadMUG) meetup on 4/16/2012.

Statistics

Views

Total Views
1,251
Views on SlideShare
1,220
Embed Views
31

Actions

Likes
1
Downloads
19
Comments
0

5 Embeds 31

http://bealetech.com 17
http://www.linkedin.com 8
http://localhost 3
http://blog.bealetech.com 2
http://organicveggie.github.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

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
  • \n
  • \n
  • - Developer at heart\n- 15 years experience\n- Responsible for selecting Mongo\n\n
  • \n
  • - Bottom-up attempt to improve student outcomes through disruptive change outside of the education system. \n- Allows students to create and store lecture notes and flashcards and access them online and via mobile apps (iOS and Android)\n
  • - No public numbers\n- Thousands of simultaneous users at peak\n
  • \n
  • \n
  • Also called “non-relational databases”\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • update() defaults to updating ~only~ the first matching document unless “multi” is set to true.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Introduction to MongoDB Introduction to MongoDB Presentation Transcript

  • StudyBlueIntroduction to MongoDBSean LaurentApril 16, 2012StudyBlue, Inc.
  • Overview • NoSQL landscape • MongoDB features • Availability & Scalability • Useful Tools • Strengths & WeaknessesStudyBlue, Inc.
  • Who am I? • Sean Laurent • sean@studyblue.com • Director of Operations at StudyBlue, Inc.StudyBlue, Inc.
  • studyblue.comStudyBlue, Inc.
  • About StudyBlue • Bottom-up attempt to improve student outcomes • Online service for storing, studying, sharing and ultimately mastering course material • Digital backpack for studentsStudyBlue, Inc.
  • StudyBlue Usage • Many simultaneous users • Rapid growth • Cyclical usageStudyBlue, Inc.
  • NoSQL Landscape:Database ModelsStudyBlue, Inc.
  • Database ModelsStudyBlue, Inc.
  • NoSQL Data Models • Key-Value stores • Document stores • Column-oriented databases • Graph databasesStudyBlue, Inc.
  • Key-Value Stores • Maps keys to values • Operations: • Get, Set and Delete • Examples: • Cassandra, Project Voldemort, memcache, RedisStudyBlue, Inc.
  • Document Stores • Contains “documents” • Documents have “fields” • Secondary indexes • Operations: • Insert, Update, Delete, Update fields • Examples: • MongoDB, CouchDBStudyBlue, Inc.
  • Column Oriented Databases • Reversed relational database • Data for column kept together • Operations: • Insert, Update, Delete; update fields • Examples: • BigTable, HBase, CStore, GreenplumStudyBlue, Inc.
  • Graph Databases • Stores edges between nodes • Operations: • Getting/Setting edges • Annotate vertices or edges • Query for paths • Examples: • GraphBase, Neo4j, VertexDBStudyBlue, Inc.
  • MongoDB:FeaturesStudyBlue, Inc.
  • Document Oriented • System holds databases • A database holds collections • A collection holds documents • A document is a set of fields written in JSON • A field is key-value pair • A key is a string • A value is a basic type, an array or another documentStudyBlue, Inc.
  • Sample Document { “author” : “sean”, “title” : “Intro to MongoDB”, “tags” : [ “mongodb”, “introduction” ], “views” : 42, “comments” : [ { “author” : “bob”, “comment” : “Best presentation EVER!” }, { “author” : “tom”, “comment” : “Way too long winded.” } ] }StudyBlue, Inc.
  • Flexible Schemas• Different documents in one collection can have different fields: { “author” : “sean”, “title” : “Intro to MongoDB” } { “author” : “sean”, “title” : “Databases At Scale”, “tags” : [ “mongodb”, “scaling” ] }StudyBlue, Inc.
  • Query Features • No joins • No transactions across documents or collections • Atomic updates • Simple query syntaxStudyBlue, Inc.
  • Query Examples db.posts.find({author: ‘sean’}) db.posts.find({author: ‘sean’}).sort({timestamp: 1}) db.posts.find({author: ‘sean’}).sort({timestamp: 1}).limit(2) db.posts.find({author: ‘sean’, tags: ‘mongodb’}) db.posts.find({author: ‘sean’, tags: {$in: [‘mongodb’, ‘intro’]}}) db.posts.find({author: ‘sean’, views: {$gt: 10}}) db.posts.find({$or: [{author: ‘sean’}, {views: ${gt: 20}]}) db.posts.find({}, {author: 1, views: 1})StudyBlue, Inc.
  • Update Examples db.posts.update({author: ‘sean’}, { $incr: {views: 1}}) db.posts.update({author: ‘sean’}, { $set: {views: 350}}) db.posts.update({author: ‘sean’}, { $push: {tags: ‘awesome’}}) db.posts.update({author: ‘sean’}, { $set: {views: 350}}, /* upsert */ true) db.posts.update({author: ‘sean’}, { $incr: {views: 1}}, /* upsert */ false, /* multi */ true)StudyBlue, Inc.
  • Indexes • B-Tree indexes • Embedded fields • Compound keys • Sparse • Unique • v2.1.0 or later support background indexingStudyBlue, Inc.
  • Official Drivers • C • C++ • Erlang • Haskell • Java • Javascript • .NET (C#, F#, PowerShell) • Perl • PHP • Python • Ruby • ScalaStudyBlue, Inc.
  • Community Supported Drivers • ActionScript 3 • Clojure • Dart • Go • Groovy • node.js • Objective C • Rails 3 • ...StudyBlue, Inc.
  • Other Cool Stuff • Aggregation • Explain • Map Reduce • Capped collections • GridFS • Geospatial indexingStudyBlue, Inc.
  • MongoDB:Availability &ScalabilityStudyBlue, Inc.
  • Replication • Replica sets • Asynchronous master/slave replication • Consists of two or more nodes that are copies of each other • Eventual consistency • Automatic failover • Automatically elects a primary (aka master) • Automatic recoveryStudyBlue, Inc.
  • Replica Set Benefits • Redundancy / Disaster Recovery • Automated failover • Read scaling • MaintenanceStudyBlue, Inc.
  • Replica Set - Read ScalingStudyBlue, Inc.
  • Replica Set Elections • Consensus Vote • Arbiters • Priorities • By default, all nodes have equal priority • Assign custom priorities for more powerful machines or specific datacenters • Highest priority amongst the most up-to-date nodes will be electedStudyBlue, Inc.
  • Sharding • Horizontal scaling (write scaling) • Automatic data partitioning & balancing • Automatic query routing • Each shard is typically a replica set • Sharding is enabled per collectionStudyBlue, Inc.
  • Shards • Shard keys define partitions • Names one or more fields that determine how the data is distributed • Order preserving - adjacent data (by key) tend to be stored on the same server • Chunks • Contiguous range of data from a particular collection • Chunks grow to a maximum size, then split into two new chunks • Automatically migrates chunks when chunk count is sufficiently imbalanced between different shardsStudyBlue, Inc.
  • Sharding ArchitectureStudyBlue, Inc.
  • Sharding Pieces • Config servers (mongoc) • Stores cluster metadata • Data about each shard and the chunks on that shard • Two-phased commits • Routing servers (mongos) • Receives client requests and routes to appropriate server(s) • Pulls state from config servers • Lightweight - run anywhere (including application servers)StudyBlue, Inc.
  • MongoDB:ToolsStudyBlue, Inc.
  • Useful Tools • mongo shell • mongostat • mongotop • Mongo Monitoring Service (MMS)StudyBlue, Inc.
  • mongo shell• Interactive Javascript shell• Part of the MongoDB installation• Issue commands & queries: ./bin/mongo mydatabase type “help” for help > db mydatabase > person = db.people.findOne( { name : "sara" } ); > person.city = "New York"; > db.people.save( person );StudyBlue, Inc.
  • mongostat• View statistics on a running mongod instanceStudyBlue, Inc.
  • mongotop• Track the amount of time a MongoDB instance spends reading and writing data on a per collection basisStudyBlue, Inc.
  • MMS • Free, cloud-based monitoring service • Charts • Dashboards • Automated alerting • http://mms.10gen.comStudyBlue, Inc.
  • MongoDB:Strengths &WeaknessesStudyBlue, Inc.
  • Good At • Horizontal scaling • High availability • Rapidly evolving schemasStudyBlue, Inc.
  • Less Good At • Drop-in replacement for existing SQL RDBMS • Highly transactional operations (e.g. OLTP) • Ad-hoc business intelligence • Durability without replica sets • Automatic sharding != perfect data distributionStudyBlue, Inc.
  • Q&AStudyBlue, Inc.
  • Contact usWeb: http://www.studyblue.comTwitter: @StudyBlueEmail: sean@studyblue.comTwitter: @organicveggie StudyBlue, Inc.