2. • Quick introduction to mongoDB
• Data modeling in
mongoDB, queries, geospatial, updates
and map reduce.
• Using a location-based app as an example
• Example works in mongoDB JS shell
2
4. MongoDB is a scalable, high-performance, open
source, document-oriented database.
• Fast Querying
• In-place updates
• Full Index Support
• Replication /High Availability
• Auto-Sharding
• Aggregation; Map/Reduce
• GridFS
4
5. MongoDB is Implemented in C++
• Windows, Linux, Mac OS-X, Solaris
Drivers are available in many languages
10gen supported
• C, C#
(.Net), C++, Erlang, Haskell, Java, JavaScript, Perl, PHP, Python, Ru
by, Scala, nodejs
• Multiple community supported drivers
5
6. RDBMS MongoDB
Table Collection
Row(s) JSON Document
Index Index
Partition Shard
Join Embedding/Linking
Schema (implied Schema)
6
7. { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
author : "Asya",
date : ISODate("2012-02-02T11:52:27.442Z"),
text : "About MongoDB...",
tags : [ "tech", "databases" ],
comments : [{
author : "Fred",
date : ISODate("2012-02-03T17:22:21.124Z"), text : "Best
Post Ever!"
}],
comment_count : 1
}
7
8. • JSON has powerful, limited set of datatypes
– Mongo extends datatypes with Date, Int types, Id, …
• MongoDB stores data in BSON
• BSON is a binary representation of JSON
– Optimized for performance and navigational abilities
– Also compression
See: bsonspec.org
8
9. • Intrinsic support for fast, iterative development
• Super low latency access to your data
• Very little CPU overhead
• No additional caching layer required
• Built in replication and horizontal scaling support
9
10. • Want to build an app where users can check in to
a location
• Leave notes or comments about that location
10
11. "As a user I want to be able to find other
locations nearby"
• Need to store locations
(Offices, Restaurants, etc)
– name, address, tags
– coordinates
– User generated content e.g. tips / notes
11
12. "As a user I want to be able to 'checkin' to a
location"
Checkins
– User should be able to 'check in' to a location
– Want to be able to generate statistics:
• Recent checkins
• Popular locations
12
27. "As a user I want to be able to 'checkin' to a
location"
Checkins
– User should be able to 'check in' to a location
– Want to be able to generate statistics:
• Recent checkins
• Popular locations
27
29. // find all users who've checked in here:
> db.users.find({"checkins.location":"Din Tai Fung"})
29
30. // find all users who've checked in here:
> db.users.find({"checkins.location":"Din Tai Fung"})
// find the last 10 checkins here?
> db.users.find({"checkins.location":"Din Tai Fung"})
.sort({"checkins.ts": -1}).limit(10)
30
31. // find all users who've checked in here:
> db.users.find({"checkins.location":"Din Tai Fung"})
// find the last 10 checkins here: - Warning!
> db.users.find({"checkins.location":"Din Tai Fung"})
.sort({"checkins.ts": -1}).limit(10)
Hard to query for last 10
31
38. • Single server
- need a strong backup plan
P
• Replica sets P S S
- High availability
- Automatic failover
38
39. • Single server
- need a strong backup plan
P
• Replica sets P S S
- High availability
- Automatic failover
• Sharded P S S
- Horizontally scale
- Auto balancing
P S S
39
40. Content Management Operational Intelligence E-Commerce
User Data Management High Volume Data Feeds
40
42. 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
42