This talk will introduce the features of MongoDB by walking through how one can building a simple location-based application using MongoDB. The talk will cover the basics of MongoDB's document model, query language, map-reduce framework and deployment architecture.
2. Agenda
•MongoDB: Data modeling, queries,
geospatial, updates, map reduce
•Using a location-based app as an example
•Example Works in MongoDB JS shell
3. Why MongoDB
• Open source
• Designed for today
• Today’s hardware / environments
• Today’s challenges
• Great developer experience
• Reliable
• Scalable
4. Use Cases
• RDBMS replacement for high-traffic web
applications
• Content Management-type applications
• Real-time analytics
• High-speed data logging
Web 2.0, Media, SaaS, Gaming, Finance, Telecom, Healthcare
10. Application Goals
(1)
Q: Current location (3) Record user
A: Places near location checkins
(2) Add user (4) Stats about
generated checkins
content
Places Check ins
11. Places v1
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011"
}
12. Places v2
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011"
}
> db.posts.find({zip: "10011"}).limit(10)
13. Places v2
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011",
tags : [ "business", "awesome" ]
}
14. Places v3
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011",
tags : [ "business", "awesome" ]
}
> db.posts.findOne({ zip: "10011",
tags: "awesome" })
15. Places v3
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011",
tags : [ "business", "awesome" ],
latlong : [40.0,72.0]
}
16. Places v3
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011",
tags : [ "business", "awesome" ],
latlong : [40.0,72.0]
}
> db.places.ensureIndex({latlong : "2d"})
17. Places v3
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011",
tags : [ "business", "awesome" ],
latlong : [40.0,72.0]
}
> db.places.ensureIndex({latlong : "2d"})
> db.places.find({latlong:{$near:[40,70]}})
18. Places v4
place1 = {
name : "10gen HQ",
address : "134 5th Avenue 3rd Floor",
city : "New York",
zip : "10011",
tags : [ "business", "awesome" ],
latlong : [40.0,72.0],
tips : [ { user : "ryan",
time : 6/26/2010,
tip : "stop by for office hours on
Wednesdays from 4-6pm"},
{.....}]
}
20. Querying Your Place
Creating Your Index
> db.places.ensureIndex({latlong : "2d"})
> db.places.ensureIndex({ tags : 1 })
> db.places.ensureIndex({ name : 1 })
21. Querying Places
Finding Places
> db.places.find({latlong:{$near:[40,70]}})
With Regular Expressions
> db.places.find({name: /^typeAheadString/ })
By Tag
> db.posts.find({tags: "business" })
22. Application Goals
(1)
Q: Current location (3) Record user
A: Places near location checkins
(2) Add user (4) Stats about
generated checkins
content
Places Check ins
23. Updating Places
Using Update to Add Tips
> db.places.update({name:"10gen HQ"},
{ $push : {tips: {user:"nosh", time:
6/26/2010, tip:"stop by for office hours on
Wednesdays from 4-6"}}}})
25. Application Goals
(1)
Q: Current location (3) Record user
A: Places near location checkins
(2) Add user (4) Stats about
generated checkins
content
Places Check ins
27. Check-Ins
checkin1 = {
place : "10gen HQ",
ts : 9/20/2010 10:12:00,
userId : <objectId of user>
}
28. Checking In
2 Operations
• Insert check in object
[checkin collection]
• Update ($push) user object
[user collection]
29. Querying Your Place
Creating Your Index
> db.checkins.ensureIndex({place:1,ts:1})
> db.checkins.ensureIndex({ ts:1 })
30. Application Goals
(1)
Q: Current location (3) Record user
A: Places near location checkins
(2) Add user (4) Stats about
generated checkins
content
Places Check ins
33. Application Goals
(1)
Q: Current location (3) Record user
(2) Add user
generated
content
:)A: Places near location checkins
(4) Stats about
checkins
Places Check ins
38. spf13.com
github.com/spf13
@spf13
Questions?
download at mongodb.org
We’re hiring!! Engineers, Sales, Evangelist, Marketing & Support
Contact us at jobs@10gen.com