27
{title : Starting with MongoDB} by César Cruz

Starting with MongoDB

Embed Size (px)

Citation preview

{title : Starting with MongoDB}

by César Cruz

About Me• In search of my Zen programming language

• Computer Engineering Student

• President ACM-ECE 2012 - 2013

• Founder hackPR @ UPRM

• Opinionated

• @sezalcru

NoSQL- Non-relational database

- Documents, Key- Value pairs, Graphs and Objects

- Dynamic Schemas

- Store object in favor of tables

- Quick setup and integration

So, MongoDB- Document oriented, NoSQL

- Document structure is similar to JSON object

- Dynamic Schema

- Forgiving

- JavaScript query language

Documents

Image courtesy of @mongoDB

Go for MongoDB when…

- Developing a quick prototype

- Quick refactoring in development

- Non-relational data

- Log data

- Metadata

Re-think MongoDB if…

- Related data***

- Joins

- Redundancy will be an issue

- Performance can be an issue

***This is a biggie

Docs and Drivers

- Open Source Project

- Great documentation and community support

- Docs at: docs.mongodb.org

- Support for almost all major languages

Installation

OSX

Using homebrew: brew install mongodb

Or

Download package from mongoDB website

Windows

Download installation package from website

Linux

Head to mongoDB website, in downloads section, select appropriate distribution.

Download package distribution

Or

sudo apt-get install -y mongodb-org

Configuration

MongoDB by default stores data in the /data/db parent directory. Create this directory using

mkdir -p /data/db

MongoDB must have read and write access to this directory

Start

Command Line Interface

MongoDB comes with a built in Command Line Interface (CLI). To start the CLI type mongo into the console. The CLI will be your best friend for debugging.

Basic Commands- Show current database: db

- Show available databases: show dbs

- Switch to database: use databaseName

- Show collections: show collections

- Basic JS Syntax

Ok, let’s assume a Collection of Articles

To define an Article, we would need, at least:

Title

Contents

Author

Date Created

An Article document would look like this:

Create

Read

Update

Delete

Create

Read

Update

Delete

Debugging

A few useful commands when debugging in mongo are:

db.stats()

db.serverStatus()

Questions?

Demo time