SlideShare a Scribd company logo
1 of 82
Download to read offline
SCALE




 Full
Metal
Mongo
• Humongous: Slang. Extraordinary large;
  expressive coinage, perhaps reflecting huge
  and monstrous, with stress pattern of
  tremendous
• Open source NoSQL database
 • Written in C++
 • https://github.com/mongodb/mongo
Production
Deployments
Outline
• Terminology and            • Schema design
  basics
                             • Indexes
• The mongo shell
                             • DBA stuff
• Insert / update / delete
                             • Security
• Querying
                             • Replica sets
• Aggregation
                             • Sharding
• Map/reduce
Terminology and basics
Terminology

• NoSQL is almost everything
• Schemaless is nonesense : mongoDB do
  have a schema
 • Flexible
 • But a schema
Scaling out
 scale
speed
           NoSQL




                       features
Format

• BSON: Binary encoded serialization of
  JSON documents
• Characteristics
 • Lightweight: minimum overhead
 • Traversable
 • Efficient: encoding and decoding
JSON
{
    _id : ObjectId(xxxxx),
    name : 'Full Metal Mongo',
    date : Date(),
    presenter: 'isra',
    attendants : [
       {name:'ana', age:23},
       {name:'luis', age: 32}
     ]
}
    //default _id: 24 hex chars
Data schema
            Database
  Collection

    Document

{ user: 1, name: [] }
Collection
• Flexible: no fixed structure
 • ALTER TABLE (implicit)
• Created in the first insertion (same for
  dbs)
• Capped collection: maintain insert order,
  fixed size
Document

• JSON document
 • _id (ObjectId)
    • unique for the collection
    • it can be a document itself
 • Fields: numeric, string, date
 • Arrays and subdocuments
SQL to Mongo mapping
MongoDB basics
• Default port: 27017
• Optional authentication
• Data location: /data/db/
• Modes
 • automatic replication
 • automatic fail-over
Drivers
• Officially supported
 • C, C++, Erlang, Haskell, Java,
    Javascript, .NET, Perl, PHP, Python, Ruby,
    Scala
• Community supported
 • ActionScript, C#, Delphi, etc.
• http://api.mongodb.org/
Connection
• mongodb://username:password@host:port/
  database?options
 • username and password are optional
 • port: 27017 by default
 • database: admin database by default
 • options: ‘name=value’ pairs
The mongo shell
Hands on:
      let’s get started

• Run a mongod (--fork) instance
• Run a mongo shell (mongo) that connects
  to this instance
The mongo shell:
          basics
• show dbs
• use db_name
• show collections (current db)
• show users (current db)
Insertion
Suppose a collection of GUL courses.

         db.courses.insert ({
           name : 'Full Metal Mongo',
           date : new Date(),
           presenter: 'isra',
           attendants : [
             {name: 'ana', age: 23},
             {name: 'luis', age: 32}
           ]
         }
Querying

//Full Metal Mongo course
db.gul.find({name:'Full Metal Mongo'})

//Courses attended by ana
db.gul.find({attendants.name:'ana'})

//Course names given by isra
db.gul.find({presenter:'isra'}, {name:1})
Querying II
//Courses ordered by name
db.gul.find().sort({name:1});

//The first 5 courses
db.gul.find().limit(5);

//Next five courses
db.gul.find().skip(5).limit(5);

//First course (natural order)
db.gul.findOne()
Querying III
//Courses attended by any under-age
db.gul.find({attendants.age:{$lt:18}});

//Last year courses between Monday and Thursday
db.gul.find({date:{
  $gt:new Date(2012,03,08),
  $lt:new Date(2012,03,11)}
});
Querying IV
//Courses attended by pedro or ana
db.gul.find({'attendants.name':
  {$in:['pedro', 'ana']}
});

//Courses attended by 10 people
db.gul.find({attendants:
  {$size:10}
});
$ operators
• $in / $nin              • $exists
• $all (default is any)   • $regex
• $gt(e) / $lt(e)         • $natural (order)
• $ne                     • $toLower / $toUpper
• $elemMatch
  (conditions in the
  same subdoc)
More $ expressions
• $sum      • $push (insert)
• $avg      • $addToSet (insert)
• $min      • $first (sort)
• $max      • $last (sort)
Update
//updates if exits; inserts if new
db.gul.save(x)

//update speakers in the crafty course
db.gul.update(
  {name:'Crafty'},
  {$set:{presenter:['javi','isra']}}
);

//new attendant to a course (not multi)
db.gul.update(
  {name:'mongoDB'},
  {attendants:
    {$push:{name:'pepe', age:19}}
  }
);
Find and Modify
• findAndModify (not widely used)
Remove
//removes all
db.gul.remove()

//search and remove
db.gul.remove({presenter:'isra'})
Database references:
     direct linking
//Query
isra = db.gul_members.findOne()

//Response from the query
{_id: ObjectId('ad234fea23482348'),
name:'isra', age:31, languages:'js'}

//Find by id
db.gul.find({'attendants._id':isra._id})
Database references:
         DBRef
//Query
isra = db.gul_members.findOne()

//Response
{_id: ObjectId('ad234fea23482348'),
name:'isra', age:31, languages:'js'}

//Insert by DBRef
db.gul.insert({
  name: 'mongoDB',
  presenter: new DBRef('gul_members',isra._id)
})
Import
              example data
     • Download a short courses collection from
      • http://www.it.uc3m.es/igrojas/mongo/
         initDB.json

//Import dataset in JSON
mongoimport --db gul --collection courses initDB.json
Hands on:
             querying
• Add a new course with data similar to the
  existing
• Update your course to add attendants
• Query courses with speaker “Jesús Espino”
• Query course on Friday
• Query courses tagged as “android”
Aggregation
    db.gul.aggregate([ pipeline ])
•    Pipelines (7)                  •   $order (1:1)

    •   $match (n:1)                •   $limit (n:1)

    •   $project (1:1)              •   $skip (n:1)

    •   $group (n:1)                •   $unwind (1:n)

    Examples: http://docs.mongodb.org/manual/reference/
    sql-aggregation-comparison/
Aggregation I

//Number of courses
db.gul.count();

//Number of courses given by isra
db.gul.count({presenter:'isra'});

//Distinct attendants to all courses
db.gul.distinct('attendants.name');
Aggregation II
db.grades.aggregate([
  {$unwind:"$scores"},
  {$match:{"scores.type":{$ne:"quiz"}}},
  {$group:{
    _id:{class_id:"$class_id",
    student_id:"$student_id"},
    score:{$avg:"$scores.score"}}
  }},
  {$group:{
    _id:{class_id:"$_id.class_id"},
    score:{$avg:"$score"}
  }},
  {$sort: {score:-1}}
])
Hands on:
         aggregation

• Distinct course speakers
• Distinct tags and count
• Number of courses per weekday
Map/Reduce

• Batch processing of data and aggregation
  operations
• Where GROUP BY was used in SQL
• Input from a collection and output going
  to a collection
Map/reduce (II)
• Courses attended per individual
var map = function(){
  for(var i in this.attendants){
    emit(this.attendants[i].name,1);
  }
}
Map/reduce (III)
• Courses attended per individual
   var reduce = function(key, values){
       var sum=0;
       for (var i in values){
         sum+=values[i];
       }
       return sum;
   }
Map/reduce (IV)
• Courses attended per individual
      db.gul.mapReduce({
        map: map,
        reduce: reduce,
        {out: {inline:1},
        query:{initial_query}}
      });
Hands on:
          map/reduce
• Update the some courses to add
  attendants
• Get all the courses attended by individual

• Distinct tags and count
Schema design
Schema Design
• Function of the data and the use case
• Decisions
 • # of collections
 • Embedding or linking
 • Indexes
 • Sharding
Relationships
• Types
 • 1:1(person:resume)
 • 1:n (city:person, post:comments)
 • m:n (teacher:student)
• Doc limit: 16MB
• Examples: school, blog
Transactions

• No transactions
 • Redesign schema
 • Implement in SW
 • Tolerate no transactions
Schema design:
         examples
• Let’s design the schema for
 • courses
 • school
 • blog / twitter
 • foursquare
Indexes
Indexes
• Objective: Query optimization
• Used in the query itself and/or the ordering
• B-Tree indexes
• _id index is automatic (unique)
   db.gul.ensureIndex({ name:1 })

   db.gul.getIndexes()

   db.gul.stats() //Size of the index
Indexes (II)
• For arrays, the index is multikey (one
  index entry per array element)
• Field names are not in indexes
//Compound indexes
db.gul.ensureIndex({ name:1, age:1})

//For nested fields (subdocs)
db.gul.ensureIndex({ attendants.name:1 })
Indexes types
• default
• unique
   db.gul.ensureIndex({name:1}, {unique:1})


• sparse
   db.gul.ensureIndex({name:1}, {sparse:1})


• TTL (time to live)
• geospatial
Indexes options

• dropDups: drop duplicate keys when
  creating the index (converted in unique)
• background: created in the background on
  primary of the replica set, in the foreground
  on secondaries
More about Indexes
• Covered index
 • query covered completely by the index
• Selectivity of an index
• Explain
   db.gul.find().explain()


• Hints
   db.gul.find().hint({name:1})
Geospatial indexes

• 2d-only
• compound indexes may be used
  db.places.ensureIndex({'loc':'2d'})

  db.places.find({loc:{
    $near:[20,40],
    $maxDistance:2}
  }).limit(50)
Creating indexes:
       examples

• Optimize our courses database
 • Think of common queries
 • Implement the convenient indexes
DBAs stuff
Backups

• mongodump / mongorestore
• copy files using your own software
  (journaling enabled required)
• replica sets: backup from secondary
Commands

db.gul.runCommand('compact')

db.runCommand({compact:'gul'})

//Run a script from the command line
mongo < path/to/script.js
Profiler
• Log queries / commands
  mongod --profile 0/1/2 --slowms 100

  //0: no
  //1: slow queries
  //2: all queries
  //slowms: threshold for type 1
Profiler (II)
• From the mongo shell
  db.getProfilingLevel() // 0-1-2

  db.getProfilingStatus() // { "was" : 0,
  "slowms" : 100 }

  db.setProfilingLevel(1,1000)



• Data stored in system.profile collection
Kill operations
• db.currentOp()
 • in progress operations
• db.killOp(op_id)
• Don’t kill
 • write ops in secondaries
 • compact
 • internal ops
Commands for dbas
• mongotop
 • time of activity per collection
 • info about total, read, write, etc.
• mongostat (command line)
 • every x seconds
 • info about insert, update, delete,
    getmore, command, flushes, mapped,
    vsize, res, faults, etc.
Security tips
Security
• mongod/mongos --auth //not from
  localhost
• Add user
 • use admin
 • db.addUser(user, passwd, [readOnly])
• Auth
 • use admin
• db.auth(user, passwd)
Types of users
• admin
 • created in the admin db
 • access to all dbs
• regular
 • access a specific db
 • read/write or readOnly
Intra-cluster security


• For replica sets, to use non-auth (faster)
  communications among the nodes
• mongod --keyFile file --replSet
Replica sets
What is a replica set?

• Info replicated among several nodes
• 1 primary
• n secondaries (min 3, to get a majority)
• When a node falls, there’s election and a
  majority is needed to select a new primary
Types of nodes in a
       replica set
• Regular
• Arbiter: decides the primary in a election
• Delayed: cannot be elected primary
• Hidden: used for analytics (not primary)
Replica set
      configuration
rs.config({ _id: 'rs_name',
  members: [{_id:0, host:host0}, {_id:1,
host: host1}, {_id:2, host: host2}]})

rs.status()

rs.slaveOk() //read form secondaries

rs.isMaster() //check primary
Write concern
• Journal: list of operations (inserts, updates)
  done, saved in disk (permanent)
• getLastError (managed by the driver)
 • w: wait until write is saved in memory
    (the app receives ack) Used to detect
    errors, like violation of a unique.
  • j: wait until write is saved in the journal
Oplog and write
         concern
• oplog.rs: capped collection with the
  operations made in the replica set, stored
  in natural order
• write concern
 • w: n, means wait response of n nodes in a
    replica set
  • w: ‘majority’, wait for the majority of the
    nodes
Sharding
What is sharding?
• Scalability
• Horizontal partitioning of a database
• A BSON document stored in ONE shard
• Shard key
 • Not unique
 • No unique fields in the collection
• Mongo offers auto-sharding
What is sharding?
• Auto balancing
• Easy addition of new machines
• Up to 1k nodes
• No single point of failure
• Automatic failover
• Select a convenient shard key
Sharding config

• Need of config servers
 • store metadata about chunks
 • mongod --configsvr
• Need mongod “routers”
 • mongos (accessed by the apps)
Sharding operations
• chunk: range of the sharding key being in a
  shard
• operations
 • split: dividing a chunk to balance the size
    of the chunks
  • migrate: moving a chunk from a shard to
    another
Sharding diagram




 via: http://www.cloudifysource.org/2012/03/25/petclinic_deepdive.html
Shard key
            selection
• Examples: choose the shard key for
 • courses
 • school
 • blog / twitter
 • foursquare
References
• MongoDB devel docs: http://
  www.mongodb.org/display/DOCS/
  Developer+Zone
• MongoDB FAQ: http://www.mongodb.org/
  display/DOCS/Developer+FAQ
• MongoDB cookbook: http://
  cookbook.mongodb.org/
References
• Kyle Banker’s blog:
 • Aggregation: http://kylebanker.com/blog/
    2009/11/mongodb-count-group/
 • e-Commerce example: http://
    kylebanker.com/blog/2010/04/30/
    mongodb-and-ecommerce/
• mongodb MOOCs (dbas and developers)
 • http://education.10gen.com
Thank you very much!
   Any questions?

More Related Content

Viewers also liked

Final version mango language database presentation
Final version mango language database presentationFinal version mango language database presentation
Final version mango language database presentationSTCC Library
 
Mongo DB Terms - Mentormate Academy
Mongo DB Terms - Mentormate AcademyMongo DB Terms - Mentormate Academy
Mongo DB Terms - Mentormate AcademyDimitar Danailov
 
MAGICDB : Mango Genetic stocks Identification and Characterisation Data Base
MAGICDB : Mango Genetic stocks Identification and Characterisation Data BaseMAGICDB : Mango Genetic stocks Identification and Characterisation Data Base
MAGICDB : Mango Genetic stocks Identification and Characterisation Data BaseSenthil Natesan
 
Genetic transformation in mango
Genetic transformation in mangoGenetic transformation in mango
Genetic transformation in mangoRajesh Pati
 
Rest api design by george reese
Rest api design by george reeseRest api design by george reese
Rest api design by george reesebuildacloud
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
Brochure Finovation 2014
Brochure Finovation 2014Brochure Finovation 2014
Brochure Finovation 2014inovenaltenor
 
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB
 

Viewers also liked (12)

Manual de como instalar mongo db en windows
Manual de  como instalar mongo db en windowsManual de  como instalar mongo db en windows
Manual de como instalar mongo db en windows
 
Final version mango language database presentation
Final version mango language database presentationFinal version mango language database presentation
Final version mango language database presentation
 
Mongo DB Terms - Mentormate Academy
Mongo DB Terms - Mentormate AcademyMongo DB Terms - Mentormate Academy
Mongo DB Terms - Mentormate Academy
 
MAGICDB : Mango Genetic stocks Identification and Characterisation Data Base
MAGICDB : Mango Genetic stocks Identification and Characterisation Data BaseMAGICDB : Mango Genetic stocks Identification and Characterisation Data Base
MAGICDB : Mango Genetic stocks Identification and Characterisation Data Base
 
Mango
MangoMango
Mango
 
Genetic transformation in mango
Genetic transformation in mangoGenetic transformation in mango
Genetic transformation in mango
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
Rest api design by george reese
Rest api design by george reeseRest api design by george reese
Rest api design by george reese
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Brochure Finovation 2014
Brochure Finovation 2014Brochure Finovation 2014
Brochure Finovation 2014
 
Mongo db
Mongo dbMongo db
Mongo db
 
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo Seattle
 

Similar to Full metal mongo

2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_newMongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewAntonio Pintus
 
Schema Design (Mongo Austin)
Schema Design (Mongo Austin)Schema Design (Mongo Austin)
Schema Design (Mongo Austin)MongoDB
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael Bright
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and PythonMike Bright
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyNETWAYS
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBSean Laurent
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDBrogerbodamer
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsMatias Cascallares
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
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
 

Similar to Full metal mongo (20)

MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
Schema Design (Mongo Austin)
Schema Design (Mongo Austin)Schema Design (Mongo Austin)
Schema Design (Mongo Austin)
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Latinoware
LatinowareLatinoware
Latinoware
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
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
 

More from Israel Gutiérrez

Make startup development great again!
Make startup development great again!Make startup development great again!
Make startup development great again!Israel Gutiérrez
 
Emoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticosEmoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticosIsrael Gutiérrez
 
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums Israel Gutiérrez
 
Learning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time TeachingLearning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time TeachingIsrael Gutiérrez
 
Jugando con websockets en nodeJS
Jugando con websockets en nodeJSJugando con websockets en nodeJS
Jugando con websockets en nodeJSIsrael Gutiérrez
 
Transfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderesTransfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderesIsrael Gutiérrez
 
Enhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanismsEnhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanismsIsrael Gutiérrez
 
Pushing the awareness envelope
Pushing the awareness envelopePushing the awareness envelope
Pushing the awareness envelopeIsrael Gutiérrez
 
Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11Israel Gutiérrez
 
JTELSS11 gradient presentation
JTELSS11 gradient presentationJTELSS11 gradient presentation
JTELSS11 gradient presentationIsrael Gutiérrez
 
Research questions by the Blueberries
Research questions by the BlueberriesResearch questions by the Blueberries
Research questions by the BlueberriesIsrael Gutiérrez
 
Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...Israel Gutiérrez
 

More from Israel Gutiérrez (16)

All you need is front
All you need is frontAll you need is front
All you need is front
 
Make startup development great again!
Make startup development great again!Make startup development great again!
Make startup development great again!
 
Emoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticosEmoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticos
 
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
 
Learning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time TeachingLearning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time Teaching
 
Jugando con websockets en nodeJS
Jugando con websockets en nodeJSJugando con websockets en nodeJS
Jugando con websockets en nodeJS
 
Transfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderesTransfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderes
 
Enhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanismsEnhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanisms
 
Pushing the awareness envelope
Pushing the awareness envelopePushing the awareness envelope
Pushing the awareness envelope
 
Stay at KU Leuven
Stay at KU LeuvenStay at KU Leuven
Stay at KU Leuven
 
Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11
 
The feedback loop revisited
The feedback loop revisitedThe feedback loop revisited
The feedback loop revisited
 
JTELSS11 gradient presentation
JTELSS11 gradient presentationJTELSS11 gradient presentation
JTELSS11 gradient presentation
 
Research questions by the Blueberries
Research questions by the BlueberriesResearch questions by the Blueberries
Research questions by the Blueberries
 
Seminario eMadrid
Seminario eMadridSeminario eMadrid
Seminario eMadrid
 
Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...
 

Recently uploaded

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Full metal mongo

  • 2. • Humongous: Slang. Extraordinary large; expressive coinage, perhaps reflecting huge and monstrous, with stress pattern of tremendous • Open source NoSQL database • Written in C++ • https://github.com/mongodb/mongo
  • 4. Outline • Terminology and • Schema design basics • Indexes • The mongo shell • DBA stuff • Insert / update / delete • Security • Querying • Replica sets • Aggregation • Sharding • Map/reduce
  • 6. Terminology • NoSQL is almost everything • Schemaless is nonesense : mongoDB do have a schema • Flexible • But a schema
  • 7. Scaling out scale speed NoSQL features
  • 8. Format • BSON: Binary encoded serialization of JSON documents • Characteristics • Lightweight: minimum overhead • Traversable • Efficient: encoding and decoding
  • 9. JSON { _id : ObjectId(xxxxx), name : 'Full Metal Mongo', date : Date(), presenter: 'isra', attendants : [ {name:'ana', age:23}, {name:'luis', age: 32} ] } //default _id: 24 hex chars
  • 10. Data schema Database Collection Document { user: 1, name: [] }
  • 11. Collection • Flexible: no fixed structure • ALTER TABLE (implicit) • Created in the first insertion (same for dbs) • Capped collection: maintain insert order, fixed size
  • 12. Document • JSON document • _id (ObjectId) • unique for the collection • it can be a document itself • Fields: numeric, string, date • Arrays and subdocuments
  • 13. SQL to Mongo mapping
  • 14. MongoDB basics • Default port: 27017 • Optional authentication • Data location: /data/db/ • Modes • automatic replication • automatic fail-over
  • 15. Drivers • Officially supported • C, C++, Erlang, Haskell, Java, Javascript, .NET, Perl, PHP, Python, Ruby, Scala • Community supported • ActionScript, C#, Delphi, etc. • http://api.mongodb.org/
  • 16. Connection • mongodb://username:password@host:port/ database?options • username and password are optional • port: 27017 by default • database: admin database by default • options: ‘name=value’ pairs
  • 18. Hands on: let’s get started • Run a mongod (--fork) instance • Run a mongo shell (mongo) that connects to this instance
  • 19. The mongo shell: basics • show dbs • use db_name • show collections (current db) • show users (current db)
  • 20. Insertion Suppose a collection of GUL courses. db.courses.insert ({ name : 'Full Metal Mongo', date : new Date(), presenter: 'isra', attendants : [ {name: 'ana', age: 23}, {name: 'luis', age: 32} ] }
  • 21. Querying //Full Metal Mongo course db.gul.find({name:'Full Metal Mongo'}) //Courses attended by ana db.gul.find({attendants.name:'ana'}) //Course names given by isra db.gul.find({presenter:'isra'}, {name:1})
  • 22. Querying II //Courses ordered by name db.gul.find().sort({name:1}); //The first 5 courses db.gul.find().limit(5); //Next five courses db.gul.find().skip(5).limit(5); //First course (natural order) db.gul.findOne()
  • 23. Querying III //Courses attended by any under-age db.gul.find({attendants.age:{$lt:18}}); //Last year courses between Monday and Thursday db.gul.find({date:{ $gt:new Date(2012,03,08), $lt:new Date(2012,03,11)} });
  • 24. Querying IV //Courses attended by pedro or ana db.gul.find({'attendants.name': {$in:['pedro', 'ana']} }); //Courses attended by 10 people db.gul.find({attendants: {$size:10} });
  • 25. $ operators • $in / $nin • $exists • $all (default is any) • $regex • $gt(e) / $lt(e) • $natural (order) • $ne • $toLower / $toUpper • $elemMatch (conditions in the same subdoc)
  • 26. More $ expressions • $sum • $push (insert) • $avg • $addToSet (insert) • $min • $first (sort) • $max • $last (sort)
  • 27. Update //updates if exits; inserts if new db.gul.save(x) //update speakers in the crafty course db.gul.update( {name:'Crafty'}, {$set:{presenter:['javi','isra']}} ); //new attendant to a course (not multi) db.gul.update( {name:'mongoDB'}, {attendants: {$push:{name:'pepe', age:19}} } );
  • 28. Find and Modify • findAndModify (not widely used)
  • 29. Remove //removes all db.gul.remove() //search and remove db.gul.remove({presenter:'isra'})
  • 30. Database references: direct linking //Query isra = db.gul_members.findOne() //Response from the query {_id: ObjectId('ad234fea23482348'), name:'isra', age:31, languages:'js'} //Find by id db.gul.find({'attendants._id':isra._id})
  • 31. Database references: DBRef //Query isra = db.gul_members.findOne() //Response {_id: ObjectId('ad234fea23482348'), name:'isra', age:31, languages:'js'} //Insert by DBRef db.gul.insert({ name: 'mongoDB', presenter: new DBRef('gul_members',isra._id) })
  • 32. Import example data • Download a short courses collection from • http://www.it.uc3m.es/igrojas/mongo/ initDB.json //Import dataset in JSON mongoimport --db gul --collection courses initDB.json
  • 33. Hands on: querying • Add a new course with data similar to the existing • Update your course to add attendants • Query courses with speaker “Jesús Espino” • Query course on Friday • Query courses tagged as “android”
  • 34. Aggregation db.gul.aggregate([ pipeline ]) • Pipelines (7) • $order (1:1) • $match (n:1) • $limit (n:1) • $project (1:1) • $skip (n:1) • $group (n:1) • $unwind (1:n) Examples: http://docs.mongodb.org/manual/reference/ sql-aggregation-comparison/
  • 35. Aggregation I //Number of courses db.gul.count(); //Number of courses given by isra db.gul.count({presenter:'isra'}); //Distinct attendants to all courses db.gul.distinct('attendants.name');
  • 36. Aggregation II db.grades.aggregate([ {$unwind:"$scores"}, {$match:{"scores.type":{$ne:"quiz"}}}, {$group:{ _id:{class_id:"$class_id", student_id:"$student_id"}, score:{$avg:"$scores.score"}} }}, {$group:{ _id:{class_id:"$_id.class_id"}, score:{$avg:"$score"} }}, {$sort: {score:-1}} ])
  • 37. Hands on: aggregation • Distinct course speakers • Distinct tags and count • Number of courses per weekday
  • 38. Map/Reduce • Batch processing of data and aggregation operations • Where GROUP BY was used in SQL • Input from a collection and output going to a collection
  • 39. Map/reduce (II) • Courses attended per individual var map = function(){ for(var i in this.attendants){ emit(this.attendants[i].name,1); } }
  • 40. Map/reduce (III) • Courses attended per individual var reduce = function(key, values){ var sum=0; for (var i in values){ sum+=values[i]; } return sum; }
  • 41. Map/reduce (IV) • Courses attended per individual db.gul.mapReduce({ map: map, reduce: reduce, {out: {inline:1}, query:{initial_query}} });
  • 42. Hands on: map/reduce • Update the some courses to add attendants • Get all the courses attended by individual • Distinct tags and count
  • 44. Schema Design • Function of the data and the use case • Decisions • # of collections • Embedding or linking • Indexes • Sharding
  • 45. Relationships • Types • 1:1(person:resume) • 1:n (city:person, post:comments) • m:n (teacher:student) • Doc limit: 16MB • Examples: school, blog
  • 46. Transactions • No transactions • Redesign schema • Implement in SW • Tolerate no transactions
  • 47. Schema design: examples • Let’s design the schema for • courses • school • blog / twitter • foursquare
  • 49. Indexes • Objective: Query optimization • Used in the query itself and/or the ordering • B-Tree indexes • _id index is automatic (unique) db.gul.ensureIndex({ name:1 }) db.gul.getIndexes() db.gul.stats() //Size of the index
  • 50. Indexes (II) • For arrays, the index is multikey (one index entry per array element) • Field names are not in indexes //Compound indexes db.gul.ensureIndex({ name:1, age:1}) //For nested fields (subdocs) db.gul.ensureIndex({ attendants.name:1 })
  • 51. Indexes types • default • unique db.gul.ensureIndex({name:1}, {unique:1}) • sparse db.gul.ensureIndex({name:1}, {sparse:1}) • TTL (time to live) • geospatial
  • 52. Indexes options • dropDups: drop duplicate keys when creating the index (converted in unique) • background: created in the background on primary of the replica set, in the foreground on secondaries
  • 53. More about Indexes • Covered index • query covered completely by the index • Selectivity of an index • Explain db.gul.find().explain() • Hints db.gul.find().hint({name:1})
  • 54. Geospatial indexes • 2d-only • compound indexes may be used db.places.ensureIndex({'loc':'2d'}) db.places.find({loc:{ $near:[20,40], $maxDistance:2} }).limit(50)
  • 55. Creating indexes: examples • Optimize our courses database • Think of common queries • Implement the convenient indexes
  • 57. Backups • mongodump / mongorestore • copy files using your own software (journaling enabled required) • replica sets: backup from secondary
  • 59. Profiler • Log queries / commands mongod --profile 0/1/2 --slowms 100 //0: no //1: slow queries //2: all queries //slowms: threshold for type 1
  • 60. Profiler (II) • From the mongo shell db.getProfilingLevel() // 0-1-2 db.getProfilingStatus() // { "was" : 0, "slowms" : 100 } db.setProfilingLevel(1,1000) • Data stored in system.profile collection
  • 61. Kill operations • db.currentOp() • in progress operations • db.killOp(op_id) • Don’t kill • write ops in secondaries • compact • internal ops
  • 62. Commands for dbas • mongotop • time of activity per collection • info about total, read, write, etc. • mongostat (command line) • every x seconds • info about insert, update, delete, getmore, command, flushes, mapped, vsize, res, faults, etc.
  • 64. Security • mongod/mongos --auth //not from localhost • Add user • use admin • db.addUser(user, passwd, [readOnly]) • Auth • use admin • db.auth(user, passwd)
  • 65. Types of users • admin • created in the admin db • access to all dbs • regular • access a specific db • read/write or readOnly
  • 66. Intra-cluster security • For replica sets, to use non-auth (faster) communications among the nodes • mongod --keyFile file --replSet
  • 68. What is a replica set? • Info replicated among several nodes • 1 primary • n secondaries (min 3, to get a majority) • When a node falls, there’s election and a majority is needed to select a new primary
  • 69. Types of nodes in a replica set • Regular • Arbiter: decides the primary in a election • Delayed: cannot be elected primary • Hidden: used for analytics (not primary)
  • 70. Replica set configuration rs.config({ _id: 'rs_name', members: [{_id:0, host:host0}, {_id:1, host: host1}, {_id:2, host: host2}]}) rs.status() rs.slaveOk() //read form secondaries rs.isMaster() //check primary
  • 71. Write concern • Journal: list of operations (inserts, updates) done, saved in disk (permanent) • getLastError (managed by the driver) • w: wait until write is saved in memory (the app receives ack) Used to detect errors, like violation of a unique. • j: wait until write is saved in the journal
  • 72. Oplog and write concern • oplog.rs: capped collection with the operations made in the replica set, stored in natural order • write concern • w: n, means wait response of n nodes in a replica set • w: ‘majority’, wait for the majority of the nodes
  • 74. What is sharding? • Scalability • Horizontal partitioning of a database • A BSON document stored in ONE shard • Shard key • Not unique • No unique fields in the collection • Mongo offers auto-sharding
  • 75. What is sharding? • Auto balancing • Easy addition of new machines • Up to 1k nodes • No single point of failure • Automatic failover • Select a convenient shard key
  • 76. Sharding config • Need of config servers • store metadata about chunks • mongod --configsvr • Need mongod “routers” • mongos (accessed by the apps)
  • 77. Sharding operations • chunk: range of the sharding key being in a shard • operations • split: dividing a chunk to balance the size of the chunks • migrate: moving a chunk from a shard to another
  • 78. Sharding diagram via: http://www.cloudifysource.org/2012/03/25/petclinic_deepdive.html
  • 79. Shard key selection • Examples: choose the shard key for • courses • school • blog / twitter • foursquare
  • 80. References • MongoDB devel docs: http:// www.mongodb.org/display/DOCS/ Developer+Zone • MongoDB FAQ: http://www.mongodb.org/ display/DOCS/Developer+FAQ • MongoDB cookbook: http:// cookbook.mongodb.org/
  • 81. References • Kyle Banker’s blog: • Aggregation: http://kylebanker.com/blog/ 2009/11/mongodb-count-group/ • e-Commerce example: http:// kylebanker.com/blog/2010/04/30/ mongodb-and-ecommerce/ • mongodb MOOCs (dbas and developers) • http://education.10gen.com
  • 82. Thank you very much! Any questions?