Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Consulting Engineer, 10gen
Norman Graham
Building your first app:
an introduction to
MongoDB
What is MongoDB
Document Database
• Not for .PDF & .DOC files
• A document is essentially an associative array
• Document == JSON object
•...
Open Source
• MongoDB is an open source project
• On GitHub
• Licensed under the AGPL
• Started & sponsored by 10gen
• Com...
Horizontally Scalable
Database Landscape
Full Featured
• Ad Hoc queries
• Real time aggregation
• Rich query capabilities
• Strongly consistent
• Geospatial featur...
http://www.mongodb.org/download
s
$ tar xvf mongodb-osx-i386-2.4.4.tar.gz
$ cd mongodb-osx-i386-2.4.4/bin
$ mkdir –p /data/db
$ ./mongod
Running MongoDB
$ mongo
MongoDB shell version: 2.4.4
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
...
RDBMS MongoDB
Table, View ➜ Collection
Row ➜ Document
Index ➜ Index
Join ➜ Embedded Document
Foreign Key ➜ Reference
Parti...
Let’s Build a Blog
First step in any application is
Determine your entities
Entities in our Blogging
System
• Users (post authors)
• Posts
• Comments
• Tags
In a relational based app
We would start by doing
schema design
Typical (relational) ERD
tag_id
tag
tags
post_id
post_title
body
post_date
post_author_uid
post_id
comment_id
comment
auth...
In a MongoDB based app
We start building our
appand let the schema evolve
MongoDB ERD
title
body
date
username
Posts
[ ] comments
[ ] tags
username
fullname
email
users
No common language
so using the shell
Working with MongoDB
user = {
username: 'ngraham',
first_name: 'Norman',
last_name: 'Graham’
}
Start with an object
(or array, hash, dict, etc)
> db.users.insert(user)
Insert the record
No collection creation
needed
> db.users.findOne()
{
"_id" : ObjectId("50804d0bd94ccab2da652599"),
"username" : "ngraham",
"first_name" : "Norman",
"las...
> db.posts.insert({
title: "Hello World",
body: "This is my first blog post",
date: new Date("2013-06-20"),
username: "ngr...
 db.posts.find().pretty()
"_id" : ObjectId("51c3bafafbd5d7261b4cdb5a"),
"title" : "Hello World",
"body" : "This is my fir...
> db.posts.find({tags:'adventure'}).pretty()
{
"_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"),
"title" : "Hello World",
"bod...
> db.posts.update({_id:
new ObjectId("51c3bcddfbd5d7261b4cdb5b")},
{$push:{comments:
{name: 'Steve Blank', comment: 'Aweso...
> db.posts.findOne({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")})
{
"_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"),
"body"...
MongoDB Drivers
http://api.mongodb.org/
Next Steps
http://docs.mongodb.org/manual/
Consulting Engineer, 10gen
Norman Graham
(norman.graham@10gen.com)
Questions?
Webinar: Building Your First App
Webinar: Building Your First App
Webinar: Building Your First App
Upcoming SlideShare
Loading in …5
×

of

Webinar: Building Your First App Slide 1 Webinar: Building Your First App Slide 2 Webinar: Building Your First App Slide 3 Webinar: Building Your First App Slide 4 Webinar: Building Your First App Slide 5 Webinar: Building Your First App Slide 6 Webinar: Building Your First App Slide 7 Webinar: Building Your First App Slide 8 Webinar: Building Your First App Slide 9 Webinar: Building Your First App Slide 10 Webinar: Building Your First App Slide 11 Webinar: Building Your First App Slide 12 Webinar: Building Your First App Slide 13 Webinar: Building Your First App Slide 14 Webinar: Building Your First App Slide 15 Webinar: Building Your First App Slide 16 Webinar: Building Your First App Slide 17 Webinar: Building Your First App Slide 18 Webinar: Building Your First App Slide 19 Webinar: Building Your First App Slide 20 Webinar: Building Your First App Slide 21 Webinar: Building Your First App Slide 22 Webinar: Building Your First App Slide 23 Webinar: Building Your First App Slide 24 Webinar: Building Your First App Slide 25 Webinar: Building Your First App Slide 26 Webinar: Building Your First App Slide 27 Webinar: Building Your First App Slide 28 Webinar: Building Your First App Slide 29 Webinar: Building Your First App Slide 30 Webinar: Building Your First App Slide 31 Webinar: Building Your First App Slide 32 Webinar: Building Your First App Slide 33 Webinar: Building Your First App Slide 34 Webinar: Building Your First App Slide 35 Webinar: Building Your First App Slide 36
Upcoming SlideShare
Dev Jumpstart: Build Your First App with MongoDB
Next
Download to read offline and view in fullscreen.

4 Likes

Share

Download to read offline

Webinar: Building Your First App

Download to read offline

This talk will introduce the features of MongoDB by walking through how one can building a simple location-based checkin application using MongoDB. The talk will cover the basics of MongoDB's document model, query language, map-reduce framework and deployment architecture.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Webinar: Building Your First App

  1. 1. Consulting Engineer, 10gen Norman Graham Building your first app: an introduction to MongoDB
  2. 2. What is MongoDB
  3. 3. Document Database • Not for .PDF & .DOC files • A document is essentially an associative array • Document == JSON object • Document == PHPArray • Document == Python Dict • Document == Ruby Hash • etc
  4. 4. Open Source • MongoDB is an open source project • On GitHub • Licensed under the AGPL • Started & sponsored by 10gen • Commercial licenses available • Contributions welcome
  5. 5. Horizontally Scalable
  6. 6. Database Landscape
  7. 7. Full Featured • Ad Hoc queries • Real time aggregation • Rich query capabilities • Strongly consistent • Geospatial features • Support for most programming languages • Flexible schema
  8. 8. http://www.mongodb.org/download s
  9. 9. $ tar xvf mongodb-osx-i386-2.4.4.tar.gz $ cd mongodb-osx-i386-2.4.4/bin $ mkdir –p /data/db $ ./mongod Running MongoDB
  10. 10. $ mongo MongoDB shell version: 2.4.4 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user > db.test.insert({text: 'Welcome to MongoDB'}) > db.test.find().pretty() { "_id" : ObjectId("51c34130fbd5d7261b4cdb55"), "text" : "Welcome to MongoDB" } Mongo Shell
  11. 11. RDBMS MongoDB Table, View ➜ Collection Row ➜ Document Index ➜ Index Join ➜ Embedded Document Foreign Key ➜ Reference Partition ➜ Shard Terminology
  12. 12. Let’s Build a Blog
  13. 13. First step in any application is Determine your entities
  14. 14. Entities in our Blogging System • Users (post authors) • Posts • Comments • Tags
  15. 15. In a relational based app We would start by doing schema design
  16. 16. Typical (relational) ERD tag_id tag tags post_id post_title body post_date post_author_uid post_id comment_id comment author_name comment_date author_email uid username fullname email post_id tag_id users posts comments post_tags
  17. 17. In a MongoDB based app We start building our appand let the schema evolve
  18. 18. MongoDB ERD title body date username Posts [ ] comments [ ] tags username fullname email users
  19. 19. No common language so using the shell
  20. 20. Working with MongoDB
  21. 21. user = { username: 'ngraham', first_name: 'Norman', last_name: 'Graham’ } Start with an object (or array, hash, dict, etc)
  22. 22. > db.users.insert(user) Insert the record No collection creation needed
  23. 23. > db.users.findOne() { "_id" : ObjectId("50804d0bd94ccab2da652599"), "username" : "ngraham", "first_name" : "Norman", "last_name" : "Graham" } Querying for the user
  24. 24. > db.posts.insert({ title: "Hello World", body: "This is my first blog post", date: new Date("2013-06-20"), username: "ngraham", tags: ["adventure", "mongodb"], comments: [] }) Creating a blog post
  25. 25.  db.posts.find().pretty() "_id" : ObjectId("51c3bafafbd5d7261b4cdb5a"), "title" : "Hello World", "body" : "This is my first blog post", "date" : ISODate("2013-06-20T00:00:00Z"), "username" : ”ngraham", "tags" : [ "adventure", "mongodb" ], "comments" : [ ] } Finding the Post
  26. 26. > db.posts.find({tags:'adventure'}).pretty() { "_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"), "title" : "Hello World", "body" : "This is my first blog post", "date" : ISODate("2013-06-20T00:00:00Z"), "username" : ”ngraham", "tags" : [ "adventure", "mongodb" ], "comments" : [ ] } Querying an Array
  27. 27. > db.posts.update({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, {$push:{comments: {name: 'Steve Blank', comment: 'Awesome Post'}}}) > Using Update to Add a Comment
  28. 28. > db.posts.findOne({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}) { "_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"), "body" : "This is my first blog post", "comments" : [ { "name" : "Steve Blank", "comment" : "Awesome Post" } ], "date" : ISODate("2013-06-20T00:00:00Z"), "tags" : [ "adventure", "mongodb" ], "title" : "Hello World", "username" : ”ngraham" } Post with Comment Attached
  29. 29. MongoDB Drivers
  30. 30. http://api.mongodb.org/
  31. 31. Next Steps
  32. 32. http://docs.mongodb.org/manual/
  33. 33. Consulting Engineer, 10gen Norman Graham (norman.graham@10gen.com) Questions?
  • kapilksharma

    Jun. 3, 2014
  • persiandeveloper

    Aug. 9, 2013
  • davi_m_moreira

    Aug. 7, 2013
  • bhushannahsuhb

    Aug. 5, 2013

This talk will introduce the features of MongoDB by walking through how one can building a simple location-based checkin application using MongoDB. The talk will cover the basics of MongoDB's document model, query language, map-reduce framework and deployment architecture.

Views

Total views

6,510

On Slideshare

0

From embeds

0

Number of embeds

2,982

Actions

Downloads

118

Shares

0

Comments

0

Likes

4

×