webinar: building your first mongodb app

46
Solutions Architect, MongoDB Rick Houlihan #MongoDB Building your first app; an introduction to MongoDB

Post on 18-Oct-2014

3.098 views

Category:

Technology


1 download

DESCRIPTION

This webinar will walk you through building a simple location-based check-in app in MongoDB. We’ll cover the basics of MongoDB’s document model, query language, map reduce framework, and deployment architecture. In this webinar you will discover: - Why MongoDB is being adopted in organizations large and small - How easy it is to start building applications with MongoDB - Key features for manipulating and accessing data - High availability and scale-out architecture

TRANSCRIPT

Page 1: Webinar: Building Your First MongoDB App

Solutions Architect, MongoDB

Rick Houlihan

#MongoDB

Building your first app;an introduction to MongoDB

Page 2: Webinar: Building Your First MongoDB App

What is MongoDB?

Page 3: Webinar: Building Your First MongoDB App

MongoDB is a ___________ database

• Document

• Open source

• High performance

• Horizontally scalable

• Full featured

Page 4: Webinar: Building Your First MongoDB App

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

Page 5: Webinar: Building Your First MongoDB App

Open Source

• MongoDB is an open source project

• On GitHub

• Licensed under the AGPL

• Started & sponsored by MongoDB Inc (formerly 10gen)

• Commercial licenses available

• Contributions welcome

Page 6: Webinar: Building Your First MongoDB App

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 = less work

Page 7: Webinar: Building Your First MongoDB App
Page 8: Webinar: Building Your First MongoDB App

Database Landscape

Page 9: Webinar: Building Your First MongoDB App

Full Featured

• Ad Hoc queries

• Real time aggregation

• Rich query capabilities

• Strongly consistent

• Geospatial features

• Support for most programming languages

• Flexible schema

Page 10: Webinar: Building Your First MongoDB App

mongodb.org/downloads

Page 11: Webinar: Building Your First MongoDB App

$ tar –z xvf mongodb-osx-x86_64-2.4.x.tgz

$ cd mongodb-osx-i386-2.4.4/bin

$ mkdir –p /data/db

$ ./mongod

Running MongoDB

Page 12: Webinar: Building Your First MongoDB App

MacBook-Air-:~ $ mongoMongoDB shell version: 2.4.4connecting to: test> db.test.insert({text: 'Welcome to MongoDB'})> db.test.find().pretty(){

"_id" : ObjectId("51c34130fbd5d7261b4cdb55"),"text" : "Welcome to MongoDB"

}

Mongo Shell

Page 13: Webinar: Building Your First MongoDB App

Document Database

Page 14: Webinar: Building Your First MongoDB App

Terminology

RDBMS MongoDB

Table, View ➜ Collection

Row ➜ Document

Index ➜ Index

Join ➜ Embedded Document

Foreign Key ➜ Reference

Partition ➜ Shard

Page 15: Webinar: Building Your First MongoDB App

Let’s Build a Blog

Page 16: Webinar: Building Your First MongoDB App

First step in any application is

Determine your entities

Page 17: Webinar: Building Your First MongoDB App

Entities in our Blogging System

• Users (post authors)

• Article

• Comments

• Tags

Page 18: Webinar: Building Your First MongoDB App

In a relational base app

We would start by doing schema design

Page 19: Webinar: Building Your First MongoDB App

Typical (relational) ERD

Page 20: Webinar: Building Your First MongoDB App

In a MongoDB based appWe start building our appand let the schema evolve

Page 21: Webinar: Building Your First MongoDB App

MongoDB ERD

Page 22: Webinar: Building Your First MongoDB App

Working With MongoDB

Page 23: Webinar: Building Your First MongoDB App

var user = {

username: ’erlichson',

first_name: ’Andrew',

last_name: ’Erlichson',

}

Start with an object (or array, hash, dict, etc)

Page 24: Webinar: Building Your First MongoDB App

>db

test

> use blog

switching to db blog

> db.users.insert( user )

Switch to Your DB

Page 25: Webinar: Building Your First MongoDB App

> db.users.insert(user)

Insert the Record

No collection creation necessary

Page 26: Webinar: Building Your First MongoDB App

> db.users.findOne()

{

"_id" : ObjectId("50804d0bd94ccab2da652599"),

"username" : ”erlichson",

"first_name" : ”Andrew",

"last_name" : ”Erlichson"

}

Find One Record

Page 27: Webinar: Building Your First MongoDB App

> db.article.insert({

title: ‘Hello World’,

body: ‘This is my first blog post’,

date: new Date(‘2013-06-20’),

username: ‘erlichson’,

tags: [‘adventure’, ‘mongodb’],

comments: [ ]

})

Creating a Blog Post

Page 28: Webinar: Building Your First MongoDB App

> db.article.find().pretty()

{"_id" : ObjectId("51c3bafafbd5d7261b4cdb5a"),"title" : "Hello World","body" : "This is my first blog post","date" : ISODate("2013-06-20T00:00:00Z"),"username" : "erlichson","tags" : [

"adventure","mongodb"

],"comments" : [ ]

}

Finding the Post

Page 29: Webinar: Building Your First MongoDB App

> db.article.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" : "erlichson","tags" : [

"adventure","mongodb"

],"comments" : [ ]

}

Querying An Array

Page 30: Webinar: Building Your First MongoDB App

> db.article.update({_id:

new ObjectId("51c3bcddfbd5d7261b4cdb5b")},

{$push:{comments:

{name: 'Steve Blank', comment: 'Awesome

Post'}}})>

Using Update to Add a Comment

Page 31: Webinar: Building Your First MongoDB App

> db.article.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" : "erlichson"

}

Post with Comment Attached

Page 32: Webinar: Building Your First MongoDB App

MongoDB Drivers

Page 33: Webinar: Building Your First MongoDB App

Real applications are not built in the shell

Page 34: Webinar: Building Your First MongoDB App

MongoDB has native bindings for over 12 languages

Page 35: Webinar: Building Your First MongoDB App
Page 36: Webinar: Building Your First MongoDB App
Page 37: Webinar: Building Your First MongoDB App

docs.mongodb.org

Page 38: Webinar: Building Your First MongoDB App

Online Training at MongoDB University

Page 39: Webinar: Building Your First MongoDB App

We've introduced a lot of concepts here

Page 40: Webinar: Building Your First MongoDB App

Schema Design @

Page 41: Webinar: Building Your First MongoDB App

Replication @

Page 42: Webinar: Building Your First MongoDB App

Indexing @

Page 43: Webinar: Building Your First MongoDB App

Sharding @

Page 44: Webinar: Building Your First MongoDB App

Questions?

Page 45: Webinar: Building Your First MongoDB App

MongoDB WorldNew York City, June 23-25

#MongoDBWorld

See what’s next in MongoDB including • MongoDB 2.6• Sharding• Replication• Aggregation

http://world.mongodb.comSave $200 with discount code THANKYOU

Page 46: Webinar: Building Your First MongoDB App

Solutions Architect, MongoDB

Rick Houlihan

#ConferenceHashtag

Thank You