Introduction to 

Agenda

  • Overview
  • RDBMS mapping terminology

  • Advantages

  • Data Modelling

  • Demonstration

  • Aggregation

Overview

  • open-source document database
  • leading NoSQL database
  • written in c++

RDBMS mapping terminology

RDBMS MongoDB
Database Database
Table Collection
Tuple/Row Document
column Field
Table Join Embedded Documents
Primary Key Primary Key (Default key _id provided by mongodb itself)

Sample

document 

MongoDB Advantages

  • Schema less

  • No complex joins

  • Structure of a single object is clear

  • Conversion / mapping of application objects to database objects not needed

Data Modelling

  • Combine objects into one document if you will use them together. 

  • Duplicate the data (but limited).

  • Do joins while write, not on read.

  • Optimize your schema for most frequent use cases.

  • Do complex aggregation in the schema

Data Modelling

RDBMS

MongoDB

Demonstration

  • Start mongoDB service
C:\mongodb\bin>mongod.exe --dbpath 
"D:\workspace\mongodb\data"
  • Run mongoDB shell
C:\mongodb\bin>mongo.exe
  • Help & Statistics
db.help()
db.stats()

Demonstration (2)

  • Create database
use DATABASE_NAME
  • Create collection
db.createCollection(name, options)
  • Insert document
db.employees.insert({"name" : "Su Tran"})

Demonstration (3)

  • Query document
db.COLLECTION_NAME.find()
db.mycol.find({"likes":{$lt:50}})
where likes < 50

is equivalent to RDBMS Where clause

Demonstration (4)

  • Query document
db.mycol.find({key1:value1, key2:value2})

RDBMS

AND

Mongo query

db.mycol.find({$or:
    [{"name":"Tuan"},{"name": "Su"}]})

OR

{$lt:50}
{$lte:50}
{$gt:50}
{$gte:50}
{$ne:50}

Aggregation

Aggregations operations process data records and return computed results

  • Aggregation Pipelines
  • Map-reduce
  • Single Purpose Aggregation Operations

Aggregation Pipelines

Map-reduce

Single Purpose Aggregation Operations

References

Introduction to MongoDB

By Su Tran

Introduction to MongoDB

  • 803