Build Application With MongoDB

27
View MongoDB Dev and Admin course details at www.edureka.co/mongodb Build application with MongoDB

Transcript of Build Application With MongoDB

Page 1: Build Application With MongoDB

View MongoDB Dev and Admin course details at www.edureka.co/mongodb

Build application with MongoDB

Page 2: Build Application With MongoDB

Slide 2 www.edureka.co/mongodbSlide 2

Objectives

At the end of this module, you will be able to

Understand the NoSQL Databases

CAP Theorem

MongoDB Introduction

MongoDB Architecture

CRUD Operations

Demo on integration of MongoDB with Java Application

Page 3: Build Application With MongoDB

Slide 3 www.edureka.co/mongodbSlide 3

Data Base Management System - History

In a last decades RDBMS have been successful in solving problems related to storing, Serving and processing data.

RDBMS are adopted for

Online transaction processing ( OLTP ) Online analytical processing ( OLAP )

RDBMS/OLTP/Real Time DSS/OLAP/DW

OracleMySQLMS SQLDB2

NetezzaSAP HanaOracle Express

But Challenges Ahead?

Page 4: Build Application With MongoDB

Slide 4 www.edureka.co/mongodbSlide 4

Challenge with ‘V’s

• Volume

• Velocity

• Variety

• Veracity

• Variability

• Volatility

• Value

RDBMS

NoSQL

Page 5: Build Application With MongoDB

Slide 5 www.edureka.co/mongodbSlide 5

Why NoSQL

Bigger Data Handling Capability :NoSQL distributed databases, allow data to be spread across thousands of commodity hardware.

Elastic scaling : Scale out the storage rather than scale up by adding commodity hardware.

No Schema or Fixed Data model :Data can be inserted in a NoSQL database without first defining a rigid database schema. So the format or data model being inserted can be changed any time, without application disruption.

Integrated Caching Facility:In order to increase data output and performance advance NoSQL techniques cache data in system memory.

Data complexity :data that is stored and managed in different locations or data centers.

Page 6: Build Application With MongoDB

Slide 6 www.edureka.co/mongodbSlide 6

Advantages of NoSQL

• Distributed Architecture: easy to scale-out, easy to manage large number of nodes

• First Reads: Satisfying ‘write once, read many times’ behaviour

• Easy Replication: The failover solution

• Higher Performance: An architecture providing much higher per-node performance than the traditional SQL-based databases

• Schema Free: Data model with dynamic and flexible schema

• Fast Development: No need of the additional ORM layer

To achieve the same, we compromise on:

No joinsNo ACID transaction

Page 7: Build Application With MongoDB

Slide 7 www.edureka.co/mongodbSlide 7

CAP theorem states that there are 3 basic requirements which exist in a special relation when designing applications for a distributed architecture.

Consistency

Availability

PartitionTolerance

CAP Theorem

This means that the system is always on (guaranteedservice availability), no downtime.

This means that the system continues to function even if thecommunication among the servers is unreliable, i.e. the serversmay be partitioned into multiple groups that cannot communicatewith one another.

This means that the data in the database remains consistent afterthe execution of an operation. For example, after an updateoperation all clients see the same data.

We must understand the CAP theorem when we talk about NoSQL databases or in fact when designing any distributed system.

Page 8: Build Application With MongoDB

Slide 8 www.edureka.co/mongodbSlide 8

CAP provides the basic requirements for a distributed system tofollow 2 of the 3 requirements.

Theoretically it is impossible to fulfill all 3 requirements.

Therefore, all the current NoSQL database follows the differentcombinations of the C, A, P from the CAP theorem.

CAP Theorem and NoSQL Databases

CA - Single site cluster, therefore all nodes are alwaysin contact. When a partition occurs, the system blocks.

CP - Some data may not be accessible, but the rest isstill consistent/accurate.

AP - System is still available under partitioning, butsome of the data returned may be inaccurate.

Page 9: Build Application With MongoDB

Slide 9 www.edureka.co/mongodbSlide 9

Basically Available indicates that the system does guarantee availability, in terms of the CAP theorem.

Basically Available

Soft State indicates that the state of the system may change over time, even without input. This is because of the eventual consistency model.

Soft State

Eventual Consistency indicates that the system will become consistent over time, given that the system doesn't receive input during that time.

Eventual Consistency

A BASE system gives up on consistency.

NoSQL Database - A BASE not ACID System

Page 10: Build Application With MongoDB

Slide 10 www.edureka.co/mongodbSlide 10

~ 150 No SQL Database are there in Market

~150

NoSQL Database – Not a Panacea

Page 11: Build Application With MongoDB

Slide 11 www.edureka.co/mongodbSlide 11

Key Value Store

Memcached

Coherence

Redis

Column

Cassandra

Hbase

Accumulo

Document Oriented

MongoDB

Couch DB

Cloudant

Graph Stores

Neo4J

Oracle NoSQL

HyperGraphDB

Types of NoSQL Databases

Page 12: Build Application With MongoDB

Slide 12 www.edureka.co/mongodbSlide 12

1000 TPS

Caching Layer

300 ~ 500 SQLTransaction

100 ~ 200 SQL Transaction

1000 TPS

WEB APPLICATION

RDBMS1

Applications Changing Data

RDBMS1

A Traditional Database Solution

Page 13: Build Application With MongoDB

Slide 13 www.edureka.co/mongodbSlide 13

WEB APPLICATION

5000 TPS

A NoSQL Database Solution

Applications Changing Data

Application grows with user base and data volume

5000 TPS

Page 14: Build Application With MongoDB

Slide 14 www.edureka.co/mongodbSlide 14

MongoDB is an Open-source database.

Developed by 10gen, for a wide variety of applications. Now it is named as MongoDB.

It is an agile database that allows schemas to change quickly as applications evolve.

Scalability, High Performance and Availability.

By leveraging in-memory computing. MongoDB’s native replicationand automated failover enableenterprise-grade reliability andoperational flexibility.

MongoDB Overview

Overview

Page 15: Build Application With MongoDB

Slide 15 www.edureka.co/mongodbSlide 15

Open Source Document Storage Object Oriented

Written in C++ Easy to Use Full Index Support

What is MongoDB?

Page 16: Build Application With MongoDB

Slide 16 www.edureka.co/mongodbSlide 16

Replication and High Availability Auto Sharding Easy Query

Map Reduce Gird FS Support from Expert

What is MongoDB? (Contd.)

MongoDB Replica set

Application

Page 17: Build Application With MongoDB

Slide 17 www.edureka.co/mongodbSlide 17

In RDBMS schema design for above requirements will have minimum 3 tables.

posts

id

title

description

url

likes

post_by

tags

id

post_id

tag

comments

Comment_id

post_id

by_user

message

date_time

likes

∞1 1

Data Modeling Example in RDBMS and MongoDB

Page 18: Build Application With MongoDB

Slide 18 www.edureka.co/mongodbSlide 18

While in MongoDB schema design will have onecollection post and has the following structure.

So while showing the data, in RDBMS we need to jointhree tables and in Mongodb data will be shown fromone collection only.

{

_id: POST_IDtitle: TITLE_OF_POST, description: POST_DESCRIPTION,by: POST_BY,url: URL_OF_POST,tags: [ TAG1, TAG2, TAG3],likes: TOTAL_LIKES, comments: [

{user:'COMMENT_BY',message: TEXT,dateCreated: DATE_TIME,like: LIKES

},{

user:'COMMENT_BY',message: TEXT,dateCreated: DATE_TIME,like: LIKES

}]

}

Data Modeling Example in RDBMS and MongoDB

Page 19: Build Application With MongoDB

Slide 19 www.edureka.co/mongodbSlide 19

RDBMS MongoDB

Database Database

Table Collection

Tuple/Row Document

Column/Attribute/Variable Field

Table Join Embedded Documents

Database Server and Client

Primary KeyPrimary Key (Default key _id provided by mongodbitself)

Mysqld/Oracle mongod

mysql/sqlplus mongo

RDBMS Terminology with MongoDB

Page 20: Build Application With MongoDB

Slide 20Slide 20Slide 20 www.edureka.co/mongodb

MongoDB Production Overview

app server app server app serverapp server

Mongos Mongos Mongos Config 1Config 2

Config 3

mongod

mongod

mongod

Shard1

mongod

mongod

mongod

Shard2

mongod

mongod

mongod

Shard3

mongod

mongod

mongod

Shard4

mongod

mongod

mongod

Shard5

mongod

mongod

mongod

Shard6

Query Router

Read/Write Operations

MongoDB Cluster

Page 21: Build Application With MongoDB

Slide 21Slide 21Slide 21 www.edureka.co/mongodb

MongoDB CRUD Introduction

MongoDB provides rich functionalities for reading and manipulating data.

CRUD stands for Create, Read, Update and Delete. These terms are the basic stuffs for all interactions with the databases.C

R

U

D

Create

Read

Update

Delete

Page 22: Build Application With MongoDB

Slide 22Slide 22Slide 22 www.edureka.co/mongodb

Database Operations

Data Operations

Query

Read Create Update Delete

Data Modification

Page 23: Build Application With MongoDB

Slide 23 www.edureka.co/mongodbSlide 23

Demo On Mongo DB

Page 24: Build Application With MongoDB

Slide 24 www.edureka.co/mongodb

LIVE Online Class

Class Recording in LMS

24/7 Post Class Support

Module Wise Quiz

Project Work

Verifiable Certificate

Course Features

Page 25: Build Application With MongoDB

Slide 25 www.edureka.co/mongodb

Questions

Page 26: Build Application With MongoDB

Slide 26Slide 26Slide 26 www.edureka.co/mongodb

MongoDB Course Structure

Module 1

» Design Goals, Architecture and Installation

Module 2

» CRUD Operations

Module 3

» Schema Design and Data Modelling

Module 4

» Administration

Module 5

» Scalability and Availability

Module 6

» Indexing and Aggregation Framework

Module 7

» Application Engineering and MongoDB Tools

Module 8

» Project, Additional Concepts and Case Studies

Page 27: Build Application With MongoDB

Slide 27 www.edureka.co/mongodb