SlideShare a Scribd company logo
Introduction to MongoDB										Silicon Valley Code Camp																			Oct 8th, 2011
Before we start……NoSQL is a movement, its not antiSQLRelational Databases have their place, but they are not the only solutionDiversify - Best tool for the jobThe footers contain quotes from the video Mongo DB is Web Scale
AgendaRelational Databases vs. NoSQLCAP Theorem MongoDB at a high levelCollections, DocumentsInserting, Querying and UpdatingOther MongoDB CommandsReplication TopologiesUsing MongoDB via a driverFew InternalsAdministration
Relational DatabasesHave been around for yearsDe-facto standard for any persistence ACID compliantRigid SchemaUsually hard to scale over a distributed network Normalization is almost always a requirementORMs tend to limit the optimizations you can do to the queries.Relational Databases were'nt built for Web Scale. They have impotence mismatch.
NoSQLWhy?Not everything can be modeled in a relational constructCluster-aware out of the box. Replication, shardingetc. is built into the coreSchemaless(Mostly) Open Source, Community supportedHigh performance by design and not ball-and-chained with ACID
CAP Theorem : Pick TwoConsistency – Each client sees the same dataAvailability – The system is always available for any reads and writesPartition Tolerance – The system can tolerate any communication failure across the network (except someone pulling the plug across the datacenters).At any given point in time, only two of the above hold true in any distributed datastore.If thats what they need to do to get those kick ass benchmarks, then its a great design.
Visual Guide to NoSQL DatabasesSource: http://blog.nahurst.com/visual-guide-to-nosql-systems
How do they make up?Usually the NoSQL databases are AP, or CP.Consistency Eventually consistentWrite concernsAvailabilityRead-only stale data
MongoDB : High LevelDocument-based DatabaseSchemalessCluster-awareEasy Querying/Javascript SupportMemory MappedDrivers in all the popular languagesExcellent developer velocity (Supported by 10gen)Durable via JournalingC-P System based on the CAP theoremMongoDB handles WebScale. You turn it on and it scales right up.
CollectionsThe closest comparison to a MongoDB Collection in the relational world is a TableA collection is not bound by a schemaA collection has a namespaceCan be a capped collectionIt contains BSON documents
DocumentsClosest comparison in the relational world is a Row in a Table.Must reside within a CollectionLooks like (structured) JSON, stored as BSON within a collectionLimited to 16MB (as of 2.0)Larger sizes supported via GridFSReference : http://www.bsonspec.org. Defined as Binary-encoded Serialization format for JSON-like Documents.
Inserting DocumentsConsole defaults to localhost port 27017show databasesshow collectionsInsert a document in a collectionBulk inserts via Javascript
Querying and Updating DocumentsQuery a documentSelect certain fieldsUsing limit, skip, sort and countUsing explainIn Place Updates$inc, $push, $pull, $pop, $slice, $in, $ninIndexing on fieldsMongoDB is a Document Database, that does not need joins. It uses Map Reduce.
Other console commandsdb.stats()db.collection.stats()db.isMaster()rs.status()db.currentOp()db.serverStatus()
Replication: Master Slave Achieved by “declaring” 1 node as the master, and “declaring” many nodes as its slavesSingle point of failure/No failoverCan add any number of slaves easilyMay need to put slaves behind a load balancer
Replication : ReplicaSetsAchieved by creating a cluster, called a replSet, and adding “members” to it.The “primary” and “secondary” roles are decided among the nodes. There is no permanent “master” or “slave”.Automatic Failover via votingArbiter may be needed if there are even number of nodes to break a tieEasy to add new membersAdding load-balancing will void failover
Accessing MongoDBProgramaticallyScalaUsing casbahCode to insert a documentCode to find/queryCode to update
Object-Document MappersMongo Drivers understand Hashes, or DBObjects. A DBObject essentially is a MapThe class needs to be converted to a DBObject, either by the developer or by the driver.Some such mappers also provide a DAO which makes it easy to perform CRUD operations.MongoMapper for RubySalat for ScalaMorphia for Java
InternalsData is memory mapped, so writes can scale as no disk IO is performed with every write.Delayed writes to the disc, default 60 seconds.Always easier to keep the indices and the working set of the data in the memory to avoid swappingPre-allocated files in incrementsSmart algorithm to add padding to the storage when the document sizes are inconsistentDurability is achieved by journaling, introduced in 1.7
Replication InternalsThe almighty Oplog – Capped CollectionActs like a tx log which the slaves or secondaries read from and apply.getmore on the primary/master every 4sFailover and votingDelayed syncUsing rs.slaveOk() to query the secondaries in a replSet
Scaling MongoDBBe smart with your schema designKnow ahead of time if the system will be read-heavy or write-heavyUse explain(), use indicesDo not fetch the entire document - select fields.Keep an eye on index misses and page faults via mongostatDenormalize- avoid links, use embeds.You can never replicate enoughHorizontal scaling via shardingIf /dev/null is faster then WebScale, I’ll use it. Does /dev/null support sharding?
BackupsLock the database for a cold backupUse filer snapshotsUse mongodump -> BSON, mongorestore to restoreUse mongoexport -> JSON, mongoimport to restoreSpare slaves always help
MonitoringMMSDeveloped by 10genMuninPlugins available to monitor MongoDB ServerNagiosFor Machine Health Check
Comparison of NoSQL SolutionsSource: http://perfectmarket.com/blog/not_only_nosql_review_solution_evaluation_guide_chart
We’re hiring!corp.ign.com/careers, and @ignjobsScalaJavaPHP/ZendRailsElasticSearchMongoDBMySQLHTML5Jquery MobileSencha TouchPhonegapWordpressActionScript/FlashRedis/MemcachedCI/CD
AboutManish Pandit Sr. Engineering Manager	IGN Entertainmenthttp://linkedin.com/in/mpandit@lobster1234

More Related Content

What's hot (20)

PPTX
Benchmarking Top NoSQL Databases: Apache Cassandra, Apache HBase and MongoDB
Athiq Ahamed
 
DOCX
MongoDB DOC v1.5
Tharun Srinivasa
 
PPT
Google Megastore
bergwolf
 
PPTX
Some key value stores using log-structure
Zhichao Liang
 
PPTX
Gfs vs hdfs
Yuval Carmel
 
PPTX
Mongodb introduction and_internal(simple)
Kai Zhao
 
PPTX
HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
Cloudera, Inc.
 
PPTX
ImpalaToGo and Tachyon integration
David Groozman
 
PPTX
MongoDB presentation
Hyphen Call
 
PDF
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
The Hive
 
PPTX
GFS & HDFS Introduction
Hariharan Ganesan
 
PPTX
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
ODP
Glusterfs and Hadoop
Shubhendu Tripathi
 
PDF
Gluster Webinar: Introduction to GlusterFS v3.3
GlusterFS
 
PDF
Hadoop architecture-tutorial
vinayiqbusiness
 
PDF
Optimizing RocksDB for Open-Channel SSDs
Javier González
 
PDF
Log Structured Merge Tree
University of California, Santa Cruz
 
PPTX
Storage talk
christkv
 
PDF
Ceph and RocksDB
Sage Weil
 
PPTX
Hardware Provisioning for MongoDB
MongoDB
 
Benchmarking Top NoSQL Databases: Apache Cassandra, Apache HBase and MongoDB
Athiq Ahamed
 
MongoDB DOC v1.5
Tharun Srinivasa
 
Google Megastore
bergwolf
 
Some key value stores using log-structure
Zhichao Liang
 
Gfs vs hdfs
Yuval Carmel
 
Mongodb introduction and_internal(simple)
Kai Zhao
 
HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
Cloudera, Inc.
 
ImpalaToGo and Tachyon integration
David Groozman
 
MongoDB presentation
Hyphen Call
 
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
The Hive
 
GFS & HDFS Introduction
Hariharan Ganesan
 
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
Glusterfs and Hadoop
Shubhendu Tripathi
 
Gluster Webinar: Introduction to GlusterFS v3.3
GlusterFS
 
Hadoop architecture-tutorial
vinayiqbusiness
 
Optimizing RocksDB for Open-Channel SSDs
Javier González
 
Log Structured Merge Tree
University of California, Santa Cruz
 
Storage talk
christkv
 
Ceph and RocksDB
Sage Weil
 
Hardware Provisioning for MongoDB
MongoDB
 

Viewers also liked (20)

PPT
E Learning 2 E
hainira
 
PDF
ΦΕΚ ΔΙΔΑΣΚΑΛΙΑΣ ΒΙΟΛΟΓΙΑΣ Α ΛΥΚΕΙΟΥ 2011-12φεκ διδασκαλιασ βιολογιασ α λυκειο...
Christos Gotzaridis
 
PPTX
Keep Our Boreal As A Sink
Dean McKeown
 
PPT
Innovation, Openness And ICTs
Acacia Research & Learning Forum 2009
 
PDF
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
PPTX
Mapping an all-weather Tour de France
dbyhundred
 
PDF
Ace ppt for asean japan energy efficient conference-final
benisuryadi
 
PPT
ΦΥΣΙΚΗ ΤΩΝ ΡΕΥΣΤΩΝ ερωτήσεις για το 2ο θέμα
Christos Gotzaridis
 
PPTX
Political Cartoon
Amy
 
KEY
第49回Php勉強会@関東 Datasource
Kaz Watanabe
 
PDF
2012 0614 mobility tech focus pres (wrt)
Bill Tomoff
 
PPTX
استخدام المدونات و الويكي في التعليم
Fawaz Gogo
 
PDF
EFFICACIA DI UN SISTEMA DI VISUALIZZAZIONE SOCIALE NELL‟INFLUENZARE UN CAMBIO...
Michele Pierangeli
 
PPTX
20150901 Mapping Yorkshire
dbyhundred
 
PDF
Calendário II Divisão Zona Sul
Sporting Clube de Tomar
 
PPT
Onlinetools&Job Search2010
Cindy Edwards
 
PDF
Θεματικη οργανωση της Φυσικής Γ΄Γυμν.
Christos Gotzaridis
 
PPTX
MongoSF 2011 - Using MongoDB for IGN's Social Platform
Manish Pandit
 
PDF
ThirdSpace: orchestrating collaborative activities in PLEs for formal learning
Yvan Peter
 
PDF
Makeup Consultations & Professional Makeup: A Beautiful Education
Lillybeth: A Beautiful Education
 
E Learning 2 E
hainira
 
ΦΕΚ ΔΙΔΑΣΚΑΛΙΑΣ ΒΙΟΛΟΓΙΑΣ Α ΛΥΚΕΙΟΥ 2011-12φεκ διδασκαλιασ βιολογιασ α λυκειο...
Christos Gotzaridis
 
Keep Our Boreal As A Sink
Dean McKeown
 
Innovation, Openness And ICTs
Acacia Research & Learning Forum 2009
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
Mapping an all-weather Tour de France
dbyhundred
 
Ace ppt for asean japan energy efficient conference-final
benisuryadi
 
ΦΥΣΙΚΗ ΤΩΝ ΡΕΥΣΤΩΝ ερωτήσεις για το 2ο θέμα
Christos Gotzaridis
 
Political Cartoon
Amy
 
第49回Php勉強会@関東 Datasource
Kaz Watanabe
 
2012 0614 mobility tech focus pres (wrt)
Bill Tomoff
 
استخدام المدونات و الويكي في التعليم
Fawaz Gogo
 
EFFICACIA DI UN SISTEMA DI VISUALIZZAZIONE SOCIALE NELL‟INFLUENZARE UN CAMBIO...
Michele Pierangeli
 
20150901 Mapping Yorkshire
dbyhundred
 
Calendário II Divisão Zona Sul
Sporting Clube de Tomar
 
Onlinetools&Job Search2010
Cindy Edwards
 
Θεματικη οργανωση της Φυσικής Γ΄Γυμν.
Christos Gotzaridis
 
MongoSF 2011 - Using MongoDB for IGN's Social Platform
Manish Pandit
 
ThirdSpace: orchestrating collaborative activities in PLEs for formal learning
Yvan Peter
 
Makeup Consultations & Professional Makeup: A Beautiful Education
Lillybeth: A Beautiful Education
 
Ad

Similar to Silicon Valley Code Camp: 2011 Introduction to MongoDB (20)

PPTX
MongoDB 2.4 and spring data
Jimmy Ray
 
PDF
Baisc introduction of mongodb for beginn
poojamehta654564
 
PDF
20-NoSQLMongoDbiig data analytics hB.pdf
ssuser2d043c
 
PPT
Introduction to MongoDB
Ravi Teja
 
PDF
Introduction to MongoDB
Justin Smestad
 
PDF
When NOT to use MongoDB
Mike Michaud
 
PPTX
MongoDB Internals
Siraj Memon
 
PPT
MongoDB Pros and Cons
johnrjenson
 
PPTX
MongoDB 3.0
Victoria Malaya
 
PPTX
Mongo db intro.pptx
JWORKS powered by Ordina
 
PDF
Mongo db transcript
foliba
 
PDF
Introduction to MongoDB
Mike Dirolf
 
PPT
Mongo Bb - NoSQL tutorial
Mohan Rathour
 
PDF
Introduction to MongoDB Basics from SQL to NoSQL
Mayur Patil
 
PPTX
MongoDB
Albin John
 
PPTX
MongoDB
Albin John
 
PDF
MongoDB at FrozenRails
Mike Dirolf
 
PDF
MongoDB.pdf
KuldeepKumar778733
 
PPTX
MongoDB
Rony Gregory
 
PPT
9. Document Oriented Databases
Fabio Fumarola
 
MongoDB 2.4 and spring data
Jimmy Ray
 
Baisc introduction of mongodb for beginn
poojamehta654564
 
20-NoSQLMongoDbiig data analytics hB.pdf
ssuser2d043c
 
Introduction to MongoDB
Ravi Teja
 
Introduction to MongoDB
Justin Smestad
 
When NOT to use MongoDB
Mike Michaud
 
MongoDB Internals
Siraj Memon
 
MongoDB Pros and Cons
johnrjenson
 
MongoDB 3.0
Victoria Malaya
 
Mongo db intro.pptx
JWORKS powered by Ordina
 
Mongo db transcript
foliba
 
Introduction to MongoDB
Mike Dirolf
 
Mongo Bb - NoSQL tutorial
Mohan Rathour
 
Introduction to MongoDB Basics from SQL to NoSQL
Mayur Patil
 
MongoDB
Albin John
 
MongoDB
Albin John
 
MongoDB at FrozenRails
Mike Dirolf
 
MongoDB.pdf
KuldeepKumar778733
 
MongoDB
Rony Gregory
 
9. Document Oriented Databases
Fabio Fumarola
 
Ad

More from Manish Pandit (20)

PDF
Disaster recovery - What, Why, and How
Manish Pandit
 
PDF
Serverless Architectures on AWS in practice - OSCON 2018
Manish Pandit
 
PDF
Disaster Recovery and Reliability
Manish Pandit
 
PDF
OAuth2 primer
Manish Pandit
 
PDF
Immutable AWS Deployments with Packer and Jenkins
Manish Pandit
 
PDF
AWS Lambda with Serverless Framework and Java
Manish Pandit
 
PDF
AWS Primer and Quickstart
Manish Pandit
 
PPTX
Securing your APIs with OAuth, OpenID, and OpenID Connect
Manish Pandit
 
PDF
Silicon Valley 2014 - API Antipatterns
Manish Pandit
 
PDF
Scalabay - API Design Antipatterns
Manish Pandit
 
PPTX
API Design Antipatterns - APICon SF
Manish Pandit
 
PPTX
Motivation : it Matters
Manish Pandit
 
PPTX
Building Apis in Scala with Playframework2
Manish Pandit
 
PPTX
Scala at Netflix
Manish Pandit
 
PPT
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
PPT
Evolving IGN’s New APIs with Scala
Manish Pandit
 
PPTX
IGN's V3 API
Manish Pandit
 
PPTX
Java and the JVM
Manish Pandit
 
PPTX
Object Oriented Programming
Manish Pandit
 
PPTX
Silicon Valley Code Camp 2011: Play! as you REST
Manish Pandit
 
Disaster recovery - What, Why, and How
Manish Pandit
 
Serverless Architectures on AWS in practice - OSCON 2018
Manish Pandit
 
Disaster Recovery and Reliability
Manish Pandit
 
OAuth2 primer
Manish Pandit
 
Immutable AWS Deployments with Packer and Jenkins
Manish Pandit
 
AWS Lambda with Serverless Framework and Java
Manish Pandit
 
AWS Primer and Quickstart
Manish Pandit
 
Securing your APIs with OAuth, OpenID, and OpenID Connect
Manish Pandit
 
Silicon Valley 2014 - API Antipatterns
Manish Pandit
 
Scalabay - API Design Antipatterns
Manish Pandit
 
API Design Antipatterns - APICon SF
Manish Pandit
 
Motivation : it Matters
Manish Pandit
 
Building Apis in Scala with Playframework2
Manish Pandit
 
Scala at Netflix
Manish Pandit
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
Evolving IGN’s New APIs with Scala
Manish Pandit
 
IGN's V3 API
Manish Pandit
 
Java and the JVM
Manish Pandit
 
Object Oriented Programming
Manish Pandit
 
Silicon Valley Code Camp 2011: Play! as you REST
Manish Pandit
 

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 

Silicon Valley Code Camp: 2011 Introduction to MongoDB

  • 1. Introduction to MongoDB Silicon Valley Code Camp Oct 8th, 2011
  • 2. Before we start……NoSQL is a movement, its not antiSQLRelational Databases have their place, but they are not the only solutionDiversify - Best tool for the jobThe footers contain quotes from the video Mongo DB is Web Scale
  • 3. AgendaRelational Databases vs. NoSQLCAP Theorem MongoDB at a high levelCollections, DocumentsInserting, Querying and UpdatingOther MongoDB CommandsReplication TopologiesUsing MongoDB via a driverFew InternalsAdministration
  • 4. Relational DatabasesHave been around for yearsDe-facto standard for any persistence ACID compliantRigid SchemaUsually hard to scale over a distributed network Normalization is almost always a requirementORMs tend to limit the optimizations you can do to the queries.Relational Databases were'nt built for Web Scale. They have impotence mismatch.
  • 5. NoSQLWhy?Not everything can be modeled in a relational constructCluster-aware out of the box. Replication, shardingetc. is built into the coreSchemaless(Mostly) Open Source, Community supportedHigh performance by design and not ball-and-chained with ACID
  • 6. CAP Theorem : Pick TwoConsistency – Each client sees the same dataAvailability – The system is always available for any reads and writesPartition Tolerance – The system can tolerate any communication failure across the network (except someone pulling the plug across the datacenters).At any given point in time, only two of the above hold true in any distributed datastore.If thats what they need to do to get those kick ass benchmarks, then its a great design.
  • 7. Visual Guide to NoSQL DatabasesSource: http://blog.nahurst.com/visual-guide-to-nosql-systems
  • 8. How do they make up?Usually the NoSQL databases are AP, or CP.Consistency Eventually consistentWrite concernsAvailabilityRead-only stale data
  • 9. MongoDB : High LevelDocument-based DatabaseSchemalessCluster-awareEasy Querying/Javascript SupportMemory MappedDrivers in all the popular languagesExcellent developer velocity (Supported by 10gen)Durable via JournalingC-P System based on the CAP theoremMongoDB handles WebScale. You turn it on and it scales right up.
  • 10. CollectionsThe closest comparison to a MongoDB Collection in the relational world is a TableA collection is not bound by a schemaA collection has a namespaceCan be a capped collectionIt contains BSON documents
  • 11. DocumentsClosest comparison in the relational world is a Row in a Table.Must reside within a CollectionLooks like (structured) JSON, stored as BSON within a collectionLimited to 16MB (as of 2.0)Larger sizes supported via GridFSReference : http://www.bsonspec.org. Defined as Binary-encoded Serialization format for JSON-like Documents.
  • 12. Inserting DocumentsConsole defaults to localhost port 27017show databasesshow collectionsInsert a document in a collectionBulk inserts via Javascript
  • 13. Querying and Updating DocumentsQuery a documentSelect certain fieldsUsing limit, skip, sort and countUsing explainIn Place Updates$inc, $push, $pull, $pop, $slice, $in, $ninIndexing on fieldsMongoDB is a Document Database, that does not need joins. It uses Map Reduce.
  • 15. Replication: Master Slave Achieved by “declaring” 1 node as the master, and “declaring” many nodes as its slavesSingle point of failure/No failoverCan add any number of slaves easilyMay need to put slaves behind a load balancer
  • 16. Replication : ReplicaSetsAchieved by creating a cluster, called a replSet, and adding “members” to it.The “primary” and “secondary” roles are decided among the nodes. There is no permanent “master” or “slave”.Automatic Failover via votingArbiter may be needed if there are even number of nodes to break a tieEasy to add new membersAdding load-balancing will void failover
  • 17. Accessing MongoDBProgramaticallyScalaUsing casbahCode to insert a documentCode to find/queryCode to update
  • 18. Object-Document MappersMongo Drivers understand Hashes, or DBObjects. A DBObject essentially is a MapThe class needs to be converted to a DBObject, either by the developer or by the driver.Some such mappers also provide a DAO which makes it easy to perform CRUD operations.MongoMapper for RubySalat for ScalaMorphia for Java
  • 19. InternalsData is memory mapped, so writes can scale as no disk IO is performed with every write.Delayed writes to the disc, default 60 seconds.Always easier to keep the indices and the working set of the data in the memory to avoid swappingPre-allocated files in incrementsSmart algorithm to add padding to the storage when the document sizes are inconsistentDurability is achieved by journaling, introduced in 1.7
  • 20. Replication InternalsThe almighty Oplog – Capped CollectionActs like a tx log which the slaves or secondaries read from and apply.getmore on the primary/master every 4sFailover and votingDelayed syncUsing rs.slaveOk() to query the secondaries in a replSet
  • 21. Scaling MongoDBBe smart with your schema designKnow ahead of time if the system will be read-heavy or write-heavyUse explain(), use indicesDo not fetch the entire document - select fields.Keep an eye on index misses and page faults via mongostatDenormalize- avoid links, use embeds.You can never replicate enoughHorizontal scaling via shardingIf /dev/null is faster then WebScale, I’ll use it. Does /dev/null support sharding?
  • 22. BackupsLock the database for a cold backupUse filer snapshotsUse mongodump -> BSON, mongorestore to restoreUse mongoexport -> JSON, mongoimport to restoreSpare slaves always help
  • 23. MonitoringMMSDeveloped by 10genMuninPlugins available to monitor MongoDB ServerNagiosFor Machine Health Check
  • 24. Comparison of NoSQL SolutionsSource: http://perfectmarket.com/blog/not_only_nosql_review_solution_evaluation_guide_chart
  • 25. We’re hiring!corp.ign.com/careers, and @ignjobsScalaJavaPHP/ZendRailsElasticSearchMongoDBMySQLHTML5Jquery MobileSencha TouchPhonegapWordpressActionScript/FlashRedis/MemcachedCI/CD
  • 26. AboutManish Pandit Sr. Engineering Manager IGN Entertainmenthttp://linkedin.com/in/mpandit@lobster1234