SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
MongoDB
Replication and Sharding

      Workshop
         by Harun Yardımcı

           @h_yardimci
What we will do today?
 - Following Replicated Shard
What is MongoDB?

●   Document-oriented database

●   in MongoDB you store JSON-like documents
    with dynamic schemas

●   Bridge the gap between key-value stores
    and relational databases
What is MongoDB?
Why MongoDB?

●   Document-oriented

●   High performance

●   High availability

●   Easy scalability

●   Rich query language + MapReduce
Use Cases
                                                   Well Suited
●   Archiving and event logging
●   Document and Content Management Systems
●   ECommerce Often in combination with an RDBMS for the final
    order processing and accounting
●   Gaming Small read/writes are a good fit for MongoDB
●   Mobile Specifically, the server-side infrastructure of mobile
    systems. Geospatial.
●   Operational data store of a web site MongoDB is very good at
    real-time inserts, updates, and queries. Specific web use
    case examples:
    ●   content management
    ●   comment storage, management, voting
    ●   user registration, profile, session data
●   Real-time stats/analytics
What is a Document?


{'id':1, 'category_name' : 'Computer'}
Mongo Data Model

Key:
  'category_name'

Value:
  'Computer'

Field: key-value pair
  'category_name':'Computer'

Document: set of fields
  {'id':1, 'category_name' : 'Computer'}
Mongo Data Model

Collection: set of documents
(say categories)
  {'id':1, 'category_name' : 'Computer'},
  {'id':2, 'category_name' : 'Mobile'},
  ...

Database: set of collections
  categories
  products
  members
Simple Usage and Introduction
First Run

$ mkdir -p /data/db/                  Create a data path
                                     and give permissions
$ chown -R mongod:mongod /data/db/

                                     Start mongod deamon
$ mongod [--dbpath /data/db/] &
$ mongo                               Connect to mongod



> show dbs
> use admin
> show collections
Intro

CRUD Operations

> use testdb
switched to db testdb
> j = { name : "deneme" };
{"name" : "deneme"}
> t = { x : 3 };
{ "x" : 3 }
> db.col.save(j);
> db.col.insert(j); /* see the error message */
> db.col.save(t);
> for (var x = 1; x <= 20; x++) db.col.save({x:x, j:x*x})
>
Intro

> db.col.find();
{ "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" }
{ "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 }
{ "_id" : ObjectId("4f971ab51c3fde3bc55f286f"), "x" : 1, "j" : 1 }
{ "_id" : ObjectId("4f971ab51c3fde3bc55f2870"), "x" : 2, "j" : 4 }
{ "_id" : ObjectId("4f971ab51c3fde3bc55f2871"), "x" : 3, "j" : 9 }
…
has more
> db.col.remove({"x":"3"});
>
The Big Picture!
Replication

Two Types of Replications
●   Master / Slave Replication
●   ReplicaSet
Master-Slave Rep.

$ mkdir -p /data/db/ms             Different data paths
$ mkdir -p /data/db/sl              for each instances


$ bin/mongod --master [--port <port>]   [--dbpath /data/masterdb/]


$ bin/mongod --slave [--port <port>] --source <masterhostname>[:<port>]
 [--dbpath /data/slavedb/]


…
> db.printReplicationInfo() - on master
> db.printSlaveReplicationInfo() - on slave
> use admin
> db.runCommand({resync: 1})
ReplicaSet - Voting

Consensus Vote
For a node to be elected primary, it must receive a
majority of votes by the following formula
                           (floor(5/2)+1)


Arbiters - {_id: 2, host: 'localhost:27019', arbiterOnly:
true}


Reachable Node – heartbeat

Each replica set is limited to 12 total nodes and 7 voting nodes.
ReplicaSet

Starting The Nodes                         myRSet

                               localhost   localhost   localhost
                                 27017       27018       27019
$ mkdir -p /data/r0             /data/r0    /data/r1    /data/r2

$ mkdir -p /data/r1
$ mkdir -p /data/r2


$ mongod --replSet myRSet --port 27017 --dbpath /data/r0
$ mongod --replSet myRSet --port 27018 --dbpath /data/r1
$ mongod --replSet myRSet --port 27019 --dbpath /data/r2
ReplicaSet

Initiating The Set


> config = {_id: 'myRSet', members: [
                          {_id: 0, host: 'localhost:27017'},
                          {_id: 1, host: 'localhost:27018'},
                          {_id: 2, host: 'localhost:27019'}]
               }
> rs.initiate(config);
{
   "info" : "Config now saved locally. Should come online in about a
minute.",
    "ok" : 1
}
> rs.status();
Sharding

Sharding Components

  ●   Shard Servers

  ●   Config Servers

  ●   mongos Router
Sharding
Sharding

$ mkdir -p /data/db/s1 /data/db/s2 /data/db/config


$ mongod --shardsvr --port 27001 --dbpath /data/db/s1 &
$ mongod --shardsvr --port 27002 --dbpath /data/db/s2 &


$ mongod --configsvr --port 27003 --dbpath /data/db/config &


$ mongos --port 27017 --configdb localhost:27003 &
Sharding

Add Shards to Config
                                  Connect to mongos to add shards


> use admin
> db.runCommand( {addShard : "localhost:27001"} );
{"ok" : 1 , "added" : "localhost:27001"}
> db.runCommand( {addShard : "localhost:27002"} );
{"ok" : 1 , "added" : "localhost:27002"}
Sharding

Enable Sharding

> db.runCommand( { enablesharding: "test_database"} );
{ "ok" : 1 }


> db.runCommand( { shardcollection :
"test_database.myCollection", key : {"_id" :1} })
{ "collectionsharded" : "test_database.myCollection",
"ok" : 1 }
ReplicaSet + Sharding

host1$ mongod --shardsvr --replSet rs_a
host2$ mongod --shardsvr --replSet rs_a          Same replica set name
host3$ mongod --shardsvr --replSet rs_a

> cfg = {
    _id : "rs_a",
    members : [
        {_id : 0, host : "host1:27018", priority : 1},
        {_id : 1, host : "host2:27018", priority : 1},
        {_id : 2, host : "host3:27018", priority : 0}
    ]
}

> rs.initiate(cfg)
ReplicaSet + Sharding

host1$ mongod --configsvr
host2$ mongod --configsvr
host3$ mongod --configsvr

$ mongos --configdb host1:27019,host2:27019,host3:27019
$ mongo

> db.adminCommand( { addShard :
"rs_a/host1:27018,host2:27018,host3:27018" } )
> db.adminCommand( { addShard :
"rs_b/host4:27018,host5:27018,host6:27018" } )
> db.adminCommand( { addShard :
"rs_c/host7:27018,host8:27018,host9:27018" } )
What is Next?

        Please
    Try it Yourself
          and
Share Your Experiences

       Thanks

Mais conteúdo relacionado

Mais procurados

MongoDB Database Replication
MongoDB Database ReplicationMongoDB Database Replication
MongoDB Database ReplicationMehdi Valikhani
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...MongoDB
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceTakahiro Inoue
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤Takahiro Inoue
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday DeveloperRoss Tuck
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2Takahiro Inoue
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structuresamix3k
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsAlexander Rubin
 

Mais procurados (20)

MongoDB Database Replication
MongoDB Database ReplicationMongoDB Database Replication
MongoDB Database Replication
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp KrennJavantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Latinoware
LatinowareLatinoware
Latinoware
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structures
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of Things
 

Destaque

MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB
 
รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....Supasate Choochaisri
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)MongoSF
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDBMongoDB
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigiReact Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigiYukiya Nakagawa
 

Destaque (8)

MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
 
รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigiReact Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
 

Semelhante a Mongodb workshop

Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo dbAmit Thakkar
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecastMasahiro Nagano
 
NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013Server Density
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Cosimo Streppone
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
OSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross LawleyOSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross LawleyNETWAYS
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHPfwso
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 

Semelhante a Mongodb workshop (20)

Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
MongoDB and DynamoDB
MongoDB and DynamoDBMongoDB and DynamoDB
MongoDB and DynamoDB
 
Mongo db roma replication and sharding
Mongo db roma replication and shardingMongo db roma replication and sharding
Mongo db roma replication and sharding
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
NoSQL Infrastructure
NoSQL InfrastructureNoSQL Infrastructure
NoSQL Infrastructure
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: Sharding
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecast
 
NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
R-House (LSRC)
R-House (LSRC)R-House (LSRC)
R-House (LSRC)
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
OSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross LawleyOSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross Lawley
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 

Mais de Harun Yardımcı

Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016Harun Yardımcı
 
"It Works On My Machine" Problem
"It Works On My Machine" Problem"It Works On My Machine" Problem
"It Works On My Machine" ProblemHarun Yardımcı
 
What you don't learn in the school
What you don't learn in the schoolWhat you don't learn in the school
What you don't learn in the schoolHarun Yardımcı
 
Scalability at Gittigidiyor
Scalability at GittigidiyorScalability at Gittigidiyor
Scalability at GittigidiyorHarun Yardımcı
 
Software Development Whats & Whys
Software Development Whats & Whys Software Development Whats & Whys
Software Development Whats & Whys Harun Yardımcı
 
Gittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak UygulamalarGittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak UygulamalarHarun Yardımcı
 

Mais de Harun Yardımcı (10)

Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
"It Works On My Machine" Problem
"It Works On My Machine" Problem"It Works On My Machine" Problem
"It Works On My Machine" Problem
 
What you don't learn in the school
What you don't learn in the schoolWhat you don't learn in the school
What you don't learn in the school
 
CFEX 2014 - DAU
CFEX 2014 - DAUCFEX 2014 - DAU
CFEX 2014 - DAU
 
Scalability at Gittigidiyor
Scalability at GittigidiyorScalability at Gittigidiyor
Scalability at Gittigidiyor
 
Software Development Whats & Whys
Software Development Whats & Whys Software Development Whats & Whys
Software Development Whats & Whys
 
Introduction to Mongodb
Introduction to MongodbIntroduction to Mongodb
Introduction to Mongodb
 
Gittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak UygulamalarGittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak Uygulamalar
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 

Último

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Mongodb workshop

  • 1. MongoDB Replication and Sharding Workshop by Harun Yardımcı @h_yardimci
  • 2. What we will do today? - Following Replicated Shard
  • 3. What is MongoDB? ● Document-oriented database ● in MongoDB you store JSON-like documents with dynamic schemas ● Bridge the gap between key-value stores and relational databases
  • 5. Why MongoDB? ● Document-oriented ● High performance ● High availability ● Easy scalability ● Rich query language + MapReduce
  • 6. Use Cases Well Suited ● Archiving and event logging ● Document and Content Management Systems ● ECommerce Often in combination with an RDBMS for the final order processing and accounting ● Gaming Small read/writes are a good fit for MongoDB ● Mobile Specifically, the server-side infrastructure of mobile systems. Geospatial. ● Operational data store of a web site MongoDB is very good at real-time inserts, updates, and queries. Specific web use case examples: ● content management ● comment storage, management, voting ● user registration, profile, session data ● Real-time stats/analytics
  • 7. What is a Document? {'id':1, 'category_name' : 'Computer'}
  • 8. Mongo Data Model Key: 'category_name' Value: 'Computer' Field: key-value pair 'category_name':'Computer' Document: set of fields {'id':1, 'category_name' : 'Computer'}
  • 9. Mongo Data Model Collection: set of documents (say categories) {'id':1, 'category_name' : 'Computer'}, {'id':2, 'category_name' : 'Mobile'}, ... Database: set of collections categories products members
  • 10. Simple Usage and Introduction
  • 11. First Run $ mkdir -p /data/db/ Create a data path and give permissions $ chown -R mongod:mongod /data/db/ Start mongod deamon $ mongod [--dbpath /data/db/] & $ mongo Connect to mongod > show dbs > use admin > show collections
  • 12. Intro CRUD Operations > use testdb switched to db testdb > j = { name : "deneme" }; {"name" : "deneme"} > t = { x : 3 }; { "x" : 3 } > db.col.save(j); > db.col.insert(j); /* see the error message */ > db.col.save(t); > for (var x = 1; x <= 20; x++) db.col.save({x:x, j:x*x}) >
  • 13. Intro > db.col.find(); { "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" } { "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 } { "_id" : ObjectId("4f971ab51c3fde3bc55f286f"), "x" : 1, "j" : 1 } { "_id" : ObjectId("4f971ab51c3fde3bc55f2870"), "x" : 2, "j" : 4 } { "_id" : ObjectId("4f971ab51c3fde3bc55f2871"), "x" : 3, "j" : 9 } … has more > db.col.remove({"x":"3"}); >
  • 15. Replication Two Types of Replications ● Master / Slave Replication ● ReplicaSet
  • 16. Master-Slave Rep. $ mkdir -p /data/db/ms Different data paths $ mkdir -p /data/db/sl for each instances $ bin/mongod --master [--port <port>] [--dbpath /data/masterdb/] $ bin/mongod --slave [--port <port>] --source <masterhostname>[:<port>] [--dbpath /data/slavedb/] … > db.printReplicationInfo() - on master > db.printSlaveReplicationInfo() - on slave > use admin > db.runCommand({resync: 1})
  • 17. ReplicaSet - Voting Consensus Vote For a node to be elected primary, it must receive a majority of votes by the following formula (floor(5/2)+1) Arbiters - {_id: 2, host: 'localhost:27019', arbiterOnly: true} Reachable Node – heartbeat Each replica set is limited to 12 total nodes and 7 voting nodes.
  • 18. ReplicaSet Starting The Nodes myRSet localhost localhost localhost 27017 27018 27019 $ mkdir -p /data/r0 /data/r0 /data/r1 /data/r2 $ mkdir -p /data/r1 $ mkdir -p /data/r2 $ mongod --replSet myRSet --port 27017 --dbpath /data/r0 $ mongod --replSet myRSet --port 27018 --dbpath /data/r1 $ mongod --replSet myRSet --port 27019 --dbpath /data/r2
  • 19. ReplicaSet Initiating The Set > config = {_id: 'myRSet', members: [ {_id: 0, host: 'localhost:27017'}, {_id: 1, host: 'localhost:27018'}, {_id: 2, host: 'localhost:27019'}] } > rs.initiate(config); { "info" : "Config now saved locally. Should come online in about a minute.", "ok" : 1 } > rs.status();
  • 20. Sharding Sharding Components ● Shard Servers ● Config Servers ● mongos Router
  • 22. Sharding $ mkdir -p /data/db/s1 /data/db/s2 /data/db/config $ mongod --shardsvr --port 27001 --dbpath /data/db/s1 & $ mongod --shardsvr --port 27002 --dbpath /data/db/s2 & $ mongod --configsvr --port 27003 --dbpath /data/db/config & $ mongos --port 27017 --configdb localhost:27003 &
  • 23. Sharding Add Shards to Config Connect to mongos to add shards > use admin > db.runCommand( {addShard : "localhost:27001"} ); {"ok" : 1 , "added" : "localhost:27001"} > db.runCommand( {addShard : "localhost:27002"} ); {"ok" : 1 , "added" : "localhost:27002"}
  • 24. Sharding Enable Sharding > db.runCommand( { enablesharding: "test_database"} ); { "ok" : 1 } > db.runCommand( { shardcollection : "test_database.myCollection", key : {"_id" :1} }) { "collectionsharded" : "test_database.myCollection", "ok" : 1 }
  • 25. ReplicaSet + Sharding host1$ mongod --shardsvr --replSet rs_a host2$ mongod --shardsvr --replSet rs_a Same replica set name host3$ mongod --shardsvr --replSet rs_a > cfg = { _id : "rs_a", members : [ {_id : 0, host : "host1:27018", priority : 1}, {_id : 1, host : "host2:27018", priority : 1}, {_id : 2, host : "host3:27018", priority : 0} ] } > rs.initiate(cfg)
  • 26. ReplicaSet + Sharding host1$ mongod --configsvr host2$ mongod --configsvr host3$ mongod --configsvr $ mongos --configdb host1:27019,host2:27019,host3:27019 $ mongo > db.adminCommand( { addShard : "rs_a/host1:27018,host2:27018,host3:27018" } ) > db.adminCommand( { addShard : "rs_b/host4:27018,host5:27018,host6:27018" } ) > db.adminCommand( { addShard : "rs_c/host7:27018,host8:27018,host9:27018" } )
  • 27. What is Next? Please Try it Yourself and Share Your Experiences Thanks