New to MongoDB? This talk will introduce the philosophy and features of MongoDB. We’ll discuss the benefits of the document-based data model that MongoDB offers by walking through how one can build a simple app to store books. We’ll cover inserting, updating, and querying the database of books. This session will jumpstart your knowledge of MongoDB development, providing you with context for the rest of the day's content.
4. MongoDB is a ___________
database
• Document
• Open source
• High performance
• Horizontally scalable
• Full featured
5. Document Database
• Not for .PDF & .DOC files
• A document is essentially an associative array
• Document = JSON object
• Document = PHP Array
• Document = Python Dict
• Document = Ruby Hash
• etc
6. Open Source
• MongoDB is an open source project
• On GitHub
• Licensed under the AGPL
• Started & sponsored by MongoDB Inc
• Commercial licenses available
• Contributions welcome
7. High Performance
• Written in C++
• Extensive use of memory-mapped files
i.e. read-through write-through memory caching.
• Runs nearly everywhere
• Data serialized as BSON (fast parsing)
• Full support for primary & secondary indexes
• Document model = agile development
9. Full Featured
• Flexible schema
• Rich ad-hoc queries
• Real time aggregation
• Strongly consistent
• Geospatial features
• Built-in automatic failover
• Horizontally scalable reads/writes
• Support for most programming languages
16. First step in any application is
Determine basic requirements
17. Basic Monitoring Requirements
• Data generated at per-second intervals
• Metrics to capture (ex. CPU, memory, IO)
• Document structure for fast writes and easy reads
18. In a relational base app
We would start by doing schema
design
19. Relational Schema Options
CPU Metrics
Memory Metrics
IO Metrics
Events
• Timestamp
• CPU metrics
• Memory metrics
• IO metrics
Or
20. In a MongoDB based app
We start with a generic model
and let the documents evolve
21. MongoDB Document Modeling
Events
Timestamp (min)
CPU []
• Second
• Metric
Memory []
• Second
• Metric
IO []
• Second
• Metric
31. Finding an Hour of Events
> db.events.find({
ts: {
$gte: ISODate(“2014-09-16T09:00:00”),
$lt: ISODate(“2014-09-16T10:00:00”)
}
}).sort({ts:1})
Find using a range and sort results
ascending
32. How do you roll up the data?
Hour Avg Cpu
0 50
1 65
2 75
3 40
4 45
5 60
6 25
… …
23 30
34. How do you scale this workload
• Replica Sets
– Add data redundancy
– Automatic failover
– Tunable durability, consistency
• Sharding
– Scale reads and writes
– Support dynamic data growth
– Automatically partitions workload
– Horizontally scalable
40. MongoDB Drivers
• Official Support for 12 languages
• Community drivers for tons more
• Drivers connect to MongoDB servers
• Drivers translate BSON into native types
• Shell is not a driver, but works like one in some ways
• Installed using typical means (npm, pecl, gem, pip)
43. Suggestions for Talks
• Talk to me at Meet the Experts
– 11 am – 12 pm
– 1 pm – 2 pm
– Or catch me in the hallway
• MongoDB for the internet of things
• Socialite the Open Source Status Feed
• The Future of MongoDB Storage