1. MongoDB Hackathon 01
Vivek A. Ganesan
vivganes@gmail.com
Big Data Gods Meetup, Santa Clara, CA May
11, 2013
2. Before we start
Copyright 2013, Vivek A. Ganesan, All rights reserved 1
o A BIG thank you to our sponsors –
Big Data Cloud
o Meeting Space
o Food + Drinks
o Consulting/Training
3. Agenda
Copyright 2013, Vivek A. Ganesan, All rights reserved 2
o Introduction
o SQL to Mongo
o Mongo Shell
o Working with Mongo Clients
o Bulk Load
4. Introduction
Copyright 2013, Vivek A. Ganesan, All rights reserved 3
o This is a hackathon, not a class
o Which means we work on stuff together
o Please consult and help your team mates
o There will be labs (that’s when we learn!)
o Talk to your team mates and figure out what problem
you want to solve
o We will be prepping our data sets for the next meetup
5. About this Meetup : Structure
Copyright 2013, Vivek A. Ganesan, All rights reserved 4
• Agile teams
• Week 1 : Introduction to Problem
• Week 2 : Algorithm + Platform
• Week 3 : Technical help
(Algorithm, Platform, Testing and
Deployment)
• Week 4 : Panel + Demo
• Showcase Startups/Experts in
the space
• Teams show demos
• Panel judges winners
• We might have prizes (needs
to be figured out)
6. Why No SQL?
Copyright 2013, Vivek A. Ganesan, All rights reserved 5
• Structured vs. Unstructured Data
• Correctness vs. Agility
• No need for Strict Consistency
• Consistency comes with a penalty
• For some applications, eventual consistency is enough
• Data Categories
• Key/Value type data
• Hierarchical relationships
• Graphs
• Horizontal Scaling
• Scale out instead of Scaling up
• CAP Theorem
• Consistency, Availability and Partition tolerance
• Pick any two!
7. Lab 1 – Installation (15 minutes)
Copyright 2013, Vivek A. Ganesan, All rights reserved 6
8. SQL to MongoDB - Concepts
Copyright 2013, Vivek A. Ganesan, All rights reserved 7
10. SQL DDL to MongoDB
Copyright 2013, Vivek A. Ganesan, All rights reserved 9
11. Lab 2 – Basic CRUD
Copyright 2013, Vivek A. Ganesan, All rights reserved 10
o In a Mongo Shell,
o Create a new database called “blog”
o Create a collection called “users”
o Insert a single user called “admin”
o Create a collection called “posts”
o Insert ten posts using a loop
o Blog data : post_title, post_body and post_tags as CSV
o Update ten posts with a created_on key and the current
timestamp
o Update the posts such that at least three posts have a “foo”
tag (use the cursor functionality to iterate)
12. Lab 3 – Mastering find
Copyright 2013, Vivek A. Ganesan, All rights reserved 11
o In a Mongo Shell,
o Figure out the difference between find and findOne
o Try find on posts without any query parameters
o Find all posts but extract only the post_title field
o List all posts but in reverse order of created_on i.e. most
recent first
o Do the same as above but paginate is sets of three
o Find all posts that contain a tag called “foo”
o Find all posts that contain “foo” and sort by created_on
13. Lab 4 – Modifiers
Copyright 2013, Vivek A. Ganesan, All rights reserved 12
o In a Mongo Shell,
o Modify “posts” collection
o Change the post_tags field to an array instead of a
CSV list
o Add a new field called view_count and set it 0
o Increment view_count by 1
o Push three new tags to the post_tags field
o Pop the last two tags added to post_tags field