SlideShare uma empresa Scribd logo
1 de 52
By Sai Kiran Kotha
Contents
Intro to MongoDB
Why use it?
Performance analysis
Documents and Collections
Querying
Schema Design
Sharding
Security
Applications
Conclusion
History
MongoDB’s name comes from the middle five letters of the
word “humongous”, meaning big data.
MongoDB was created by the founders (Eliot and Dwight) of
DoubleClick.
Development of MongoDB began in October 2007 by 10gen.
In 2009, MongoDB was open sourced as a stand-alone
product with an AGPL license.
In March 2011, from version 1.4, MongoDB has been
considered production ready.
What is MongoDB?
Scalable, High-Performance, Open-Source, NoSQL Document
orientated database designed with both scalability and
developer agility in mind. It is written in C++ & built for speed.
Features:
Rich Document based queries for Easy readability.
Full Index Support for High Performance.
Replication and Failover for High Availability.
Auto Sharding for Easy Scalability.
Map / Reduce for Aggregation.
Why use MongoDB?
SQL was invented in the 70’s to store data.
MongoDB stores documents (or) objects.
Now-a-days, everyone works with objects
(Python/Ruby/Java/etc.).
And we need Databases to persist our objects. Then
why not store objects directly ?
Embedded documents and arrays reduce need for
joins. No Joins and No-multi document transactions.
TrendsinPopularityof BigDataConnectors
Performance Analysis
Anywhere from 2 to 10 times faster than SQL
MongoDB overSQLServer(orMySqlorOracle)
MongoDB overSQLServer(orMySqlorOracle)
RDBMS vs Mongodb
Collection
Schema-less(or more accurately, "dynamic schema“)
Contains Documents.
Indexable by one/more keys.
Created on-the-fly when referenced for the first time.
Capped Collections: Fixed size, older records get dropped
after reaching the limit.
Document
Stored in a Collection.
Can have _id key – works like Primary keys in MySQL.
Supported Relationships – Embedded (or) References.
.
Document storage in BSON (Binary form of JSON)via
GridFS (i.e. stores images, videos, anything...).
Embedded Objects
Documents can embed other documents
For example:
{
name: 'Brad Majors',
address:
{
street: 'Oak Terrace',
city: 'Denton'
}
}
Querying
Query Expression Objects:
MongoDB supports a number of query objects for fetching data.
Simple query:
db.users.find({})
More selective:
db.users.find({'last_name': 'Smith'})
Query Options:
Field Selection:
// retrieve ssn field for documents where last_name == 'Smith':
db.users.find({last_name: 'Smith'}, {'ssn': 1});
// retrieve all fields *except* the thumbnail field, for all
documents: db.users.find({}, {thumbnail:0});
Sorting:
db.users.find({}).sort({last_name: 1});
// return all documents and sort by last name in ascending
order
Skip and Limit:
db.users.find().skip(20).limit(10);
//skips the first 20 last names, and limit our result set to 10
db.users.find({}, {}, 10, 20);
// same as above, but less clear
Cursors: Used to iteratively retrieve all the documents returned
by the query.
>var cur = db.example.find();
> cur.forEach( function(x) { print(tojson(x))});
{"n" : 1 , "_id" : "497ce96f395f2f052a494fd4"}
{"n" : 2 , "_id" : "497ce971395f2f052a494fd5"}
Queries
Insert
db.myCollection.save({key1: "value1", key2: "value2"})
db.myCollection.save({firstname: "Foo", lastname: "Bar",
address: {Street: "Foo", City: "Bar"}})
Read
db.myCollection.find({lastname: "Meier"}, {firstname:
true}).limit(10).skip(20)
Update
db.myCollection.update({id: 123}, {$set : {a : 4}})
Delete
db.myCollection.remove({firstname: "Hans"});
Advanced Queries
Conditional operators
• db.things.find({j : {$lt: 3}});
More operators: $lte, $gt, $gte $all, $any, $or, $and, $size &
more
Nested query
• db.persons.insert(firstname: "Meier", loves:
['apple', 'orange', 'tomato'])
• db.persons.find($or: [{loves: 'apple'}, {loves:
'orange'}])
JavaScript expression
• db.myCollection.find( { $where: "this.a > 3" } );
Query examples
-usingembeddeddocuments&referenceddocuments
Exact match an entire embedded object
db.users.find( {address: {street: 'Oak Terrace',
city: 'Denton'}} )
Dot-notation for a partial match
db.users.find( {"address.city": 'Denton'} )
Allows us to deep, nested queries
db.order.find( { shipping: { carrier: "usps" } }
);
here shipping is an embedded document (object)
Schema Design
There is no predefined schema, dynamic schema.
Application creates an ad-hoc schema with the objects it creates
The schema is implicit in the queries
Collections to represent the top-level classes
Less normalization, more embedding
Traditional RDBMS schema:
MongoDB:
It depicts the Shapes object stored in the form of JSON type
document.
This eliminates the storage space involved in creating columns
and rows.
Better Schema Design: Embedding
Collection for posts
Embed comments, author name
post = {
author: 'Michael Arrington',
text: 'This is a pretty awesome post.',
comments: [
'Whatever this post.',
'I agree, lame!'
]
}
Schema Design Limitations
No referential integrity
High degree of denormalization means updating
something in many places instead of one
Lack of predefined schema is a double-edged sword
Should have model in the application
Objects within a collection can be completely inconsistent in
their fields
MongoDB Admin UI's
Some UI's are available as separate community projects and are
listed below. Some are focused on administration, while some focus
on data viewing.
Tools
MongoExplorer
MongoVUE
PHPMoAdmin
Meclipse
Commercial
Database Master
Data Viewers
mongs
MongoVue:
MongoVUE is a .NET GUI for MongoDB. It is elegant and highly
usable GUI interface to work with MongoDB. It helps in
managing web-scale data.
Database Master
Database Master from Nucleon Software
Features:
Tree view for dbs and collections
Create/Drop indexes
Server/DB stats
Sharding
Data is split up into chunks, each is assigned to a
shard
Shard: Single server or Replica set
Config Servers: Store meta data about chunks
and data location
Mongos: Routes requests in a transparent way
Replica Sets
Some Cool features
Geo-spatial Indexes for Geo-spatial queries.
$near, $within_distance, Bound queries (circle, box)
GridFS
Stores Large Binary Files.
Map/Reduce
GROUP BY in SQL, map/reduce in MongoDB.
Map/Reduce
Data processing . It has some basic aggregation capabilities.
Parallelized for working with large sets of data.
mapReduce takes a map function, a reduce function and an
output directive.
Map Funtion : A master node takes an input. Splits it into
smaller sections. Sends it to the associated nodes.
These nodes may perform the same operation in turn to
send those smaller section of input to other nodes. It
process the problem (taken as input) and sends it back to
the Master Node.
Reduce Function:
The master node aggregates those results to find the output.
Then, we can use the mapReduce command against some
hits collection by:
> db.hits.mapReduce(map, reduce,{out: {inline:1}});
We could instead specify {out: 'hit_stats'} and have the results
stored in the hit_stats collections:
> db.hits.mapReduce(map, reduce,{out:'hit_stats'});
> db.hit_stats.find();
Map/Reduce contd...
Mongodb Security
Trusted environment is default.
The current version of Mongo supports only basic security.
We can authenticate a username and password in the context
of a particular database.
Once authenticated, a normal user has full read and write
access to the database.
$ ./mongo
> use admin
> db.auth("someAdminUser", password) .
Mongodb Security contd..
If there are no admin users, we should first create an
administrator user for the entire db server process. This user is
stored under the special admin database.
One may access the database from the localhost interface
without authenticating.
Thus, from the server running the database configure an
administrative user:
$ ./mongo
> use admin
> db.addUser("theadmin", "anadminpassword")
Mongodb Security contd..
Now, let's configure a "regular" user for another database.
> use projectx
> db.addUser("joe", "passwordForJoe")
Finally, let's add a readonly user.
> use projectx
> db.addUser("guest", "passwordForGuest", true)
Cool uses
Data Warehouse
Mongo understands JSON natively
Very powerful for analysis
Query a bunch of data from web service
Import into mongo (mongoimport –f filename.json)
Harmonyapp.com
Large rails app for building websites (kind of a CMS)
Hardcore debugging
Spit out large amounts of data
Applications
RDBMS replacement for Web Applications.
Semi-structured Content Management.
Real-time Analytics & High-Speed Logging.
Caching and High Scalability.
Web 2.0, Media, SAAS, Gaming
HealthCare, Finance, Telecom, Government
Some Companies using MongoDB in Production
Conclusion
MongoDB is fast.
It achieves high performance.
It bridges the gap between traditional RDBMS at one end and
Key-Value pair search engines at the other end.
Document model is simple but powerful.
Advanced features like map/reduce, geospatial indexing etc. are
very compelling.
Very rapid development, open source & surprisingly great
drivers for most languages.
Bibliography
The required information is extracted from the following
websites:-
www.wikipedia.org
http://www.mongodb.org/
http://www.10gen.com/
http://www.w3resource.com/mongodb/introduction-
mongodb.php
http://www.jaspersoft.com/bigdata#bigdata-middle-tab-5
http://blog.michaelckennedy.net/2010/04/29/mongodb-vs-sql-
server-2008-performance-showdown/
http://blog.iprofs.nl/2011/11/25/is-mongodb-a-good-
alternative-to-rdbms-databases-like-oracle-and-mysql/
introtomongodb
introtomongodb

Mais conteúdo relacionado

Mais procurados

Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBMongoDB
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Tobias Trelle
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDBMongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaMongoDB
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...MongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDBDoThinger
 
Jaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesJaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesMassimiliano Dessì
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBTobias Trelle
 
Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkitpetertmarks
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDBTim Callaghan
 

Mais procurados (20)

Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
AngularJS By Vipin
AngularJS By VipinAngularJS By Vipin
AngularJS By Vipin
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db queries
Mongo db queriesMongo db queries
Mongo db queries
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
 
Mongo db operations_v2
Mongo db operations_v2Mongo db operations_v2
Mongo db operations_v2
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDB
 
Jaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesJaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best Practices
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
 
Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkit
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB
 

Destaque

Pedagogy for all aug 30 2010 supplemental day
Pedagogy for all aug 30 2010 supplemental dayPedagogy for all aug 30 2010 supplemental day
Pedagogy for all aug 30 2010 supplemental dayAlmai Malit-Idler
 
Course module biotech_1_it
Course module biotech_1_itCourse module biotech_1_it
Course module biotech_1_itrupalidhir
 
투이컨설팅 제12회 Y세미나 : 설문결과
투이컨설팅 제12회 Y세미나 : 설문결과투이컨설팅 제12회 Y세미나 : 설문결과
투이컨설팅 제12회 Y세미나 : 설문결과2econsulting
 
C&I Cosmic Conflict
C&I Cosmic ConflictC&I Cosmic Conflict
C&I Cosmic ConflictDan
 
투이컨설팅 제20회 Y세미나 : 설문결과
투이컨설팅 제20회 Y세미나 : 설문결과투이컨설팅 제20회 Y세미나 : 설문결과
투이컨설팅 제20회 Y세미나 : 설문결과2econsulting
 
Presentation1'
Presentation1'Presentation1'
Presentation1'tommydjfx
 
Смятение чувств
Смятение чувствСмятение чувств
Смятение чувствPeugeotUA
 
Picasso Vl Advertising Supplement 1
Picasso Vl Advertising Supplement 1Picasso Vl Advertising Supplement 1
Picasso Vl Advertising Supplement 1mbushong
 
CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...
CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...
CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...Chicago eLearning & Technology Showcase
 
EclipseCon USA 2011 Virgo Snaps
EclipseCon USA 2011 Virgo SnapsEclipseCon USA 2011 Virgo Snaps
EclipseCon USA 2011 Virgo SnapsChristopher Frost
 
TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011
TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011
TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011Technopreneurs Association of Malaysia
 
Full portfolio 2010.indb
Full portfolio 2010.indbFull portfolio 2010.indb
Full portfolio 2010.indbfontingyu
 
Raport o ruchu_rowerowym-nr_1
Raport o ruchu_rowerowym-nr_1Raport o ruchu_rowerowym-nr_1
Raport o ruchu_rowerowym-nr_1Robert
 

Destaque (20)

Pedagogy for all aug 30 2010 supplemental day
Pedagogy for all aug 30 2010 supplemental dayPedagogy for all aug 30 2010 supplemental day
Pedagogy for all aug 30 2010 supplemental day
 
Malaysia Freight Logistics: The Way Forward
Malaysia Freight Logistics: The Way ForwardMalaysia Freight Logistics: The Way Forward
Malaysia Freight Logistics: The Way Forward
 
Bob brown
Bob brownBob brown
Bob brown
 
Course module biotech_1_it
Course module biotech_1_itCourse module biotech_1_it
Course module biotech_1_it
 
투이컨설팅 제12회 Y세미나 : 설문결과
투이컨설팅 제12회 Y세미나 : 설문결과투이컨설팅 제12회 Y세미나 : 설문결과
투이컨설팅 제12회 Y세미나 : 설문결과
 
C&I Cosmic Conflict
C&I Cosmic ConflictC&I Cosmic Conflict
C&I Cosmic Conflict
 
투이컨설팅 제20회 Y세미나 : 설문결과
투이컨설팅 제20회 Y세미나 : 설문결과투이컨설팅 제20회 Y세미나 : 설문결과
투이컨설팅 제20회 Y세미나 : 설문결과
 
Guangzhou
GuangzhouGuangzhou
Guangzhou
 
Presentation1'
Presentation1'Presentation1'
Presentation1'
 
Смятение чувств
Смятение чувствСмятение чувств
Смятение чувств
 
Picasso Vl Advertising Supplement 1
Picasso Vl Advertising Supplement 1Picasso Vl Advertising Supplement 1
Picasso Vl Advertising Supplement 1
 
CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...
CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...
CETS 2011, Brigitte Barrett-Johnston, slides for Developing an eLearning Curr...
 
EclipseCon USA 2011 Virgo Snaps
EclipseCon USA 2011 Virgo SnapsEclipseCon USA 2011 Virgo Snaps
EclipseCon USA 2011 Virgo Snaps
 
Two Studies of Consumer Reviews
Two Studies of Consumer ReviewsTwo Studies of Consumer Reviews
Two Studies of Consumer Reviews
 
Africa and Southeast Asia Business Forum 2011
Africa and Southeast Asia Business Forum 2011Africa and Southeast Asia Business Forum 2011
Africa and Southeast Asia Business Forum 2011
 
TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011
TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011
TeAM and iSentric - Mobile Business Commercialization Program - 31st Mar 2011
 
Pharma
PharmaPharma
Pharma
 
My first quiz
My first quizMy first quiz
My first quiz
 
Full portfolio 2010.indb
Full portfolio 2010.indbFull portfolio 2010.indb
Full portfolio 2010.indb
 
Raport o ruchu_rowerowym-nr_1
Raport o ruchu_rowerowym-nr_1Raport o ruchu_rowerowym-nr_1
Raport o ruchu_rowerowym-nr_1
 

Semelhante a introtomongodb

Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
Introduction to MongoDB and its best practices
Introduction to MongoDB and its best practicesIntroduction to MongoDB and its best practices
Introduction to MongoDB and its best practicesAshishRathore72
 
MongoDB - A next-generation database that lets you create applications never ...
MongoDB - A next-generation database that lets you create applications never ...MongoDB - A next-generation database that lets you create applications never ...
MongoDB - A next-generation database that lets you create applications never ...Ram Murat Sharma
 
MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling Sachin Bhosale
 
Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)MongoDB
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011bostonrb
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductiondinkar thakur
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductionsethfloydjr
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellShahDhruv21
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBSQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBMarco Segato
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
MongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDB
MongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDBMongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDB
MongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDBMongoDB
 

Semelhante a introtomongodb (20)

Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Introduction to MongoDB and its best practices
Introduction to MongoDB and its best practicesIntroduction to MongoDB and its best practices
Introduction to MongoDB and its best practices
 
MongoDB - A next-generation database that lets you create applications never ...
MongoDB - A next-generation database that lets you create applications never ...MongoDB - A next-generation database that lets you create applications never ...
MongoDB - A next-generation database that lets you create applications never ...
 
MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling
 
Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Mongo db
Mongo dbMongo db
Mongo db
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shell
 
MongoDB
MongoDBMongoDB
MongoDB
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBSQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDB
MongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDBMongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDB
MongoDB World 2018: Bumps and Breezes: Our Journey from RDBMS to MongoDB
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
Mongodb Introduction
Mongodb Introduction Mongodb Introduction
Mongodb Introduction
 

introtomongodb

  • 1. By Sai Kiran Kotha
  • 2. Contents Intro to MongoDB Why use it? Performance analysis Documents and Collections Querying Schema Design Sharding Security Applications Conclusion
  • 3.
  • 4. History MongoDB’s name comes from the middle five letters of the word “humongous”, meaning big data. MongoDB was created by the founders (Eliot and Dwight) of DoubleClick. Development of MongoDB began in October 2007 by 10gen. In 2009, MongoDB was open sourced as a stand-alone product with an AGPL license. In March 2011, from version 1.4, MongoDB has been considered production ready.
  • 5. What is MongoDB? Scalable, High-Performance, Open-Source, NoSQL Document orientated database designed with both scalability and developer agility in mind. It is written in C++ & built for speed. Features: Rich Document based queries for Easy readability. Full Index Support for High Performance. Replication and Failover for High Availability. Auto Sharding for Easy Scalability. Map / Reduce for Aggregation.
  • 6.
  • 7. Why use MongoDB? SQL was invented in the 70’s to store data. MongoDB stores documents (or) objects. Now-a-days, everyone works with objects (Python/Ruby/Java/etc.). And we need Databases to persist our objects. Then why not store objects directly ? Embedded documents and arrays reduce need for joins. No Joins and No-multi document transactions.
  • 9.
  • 10. Performance Analysis Anywhere from 2 to 10 times faster than SQL
  • 13.
  • 15. Collection Schema-less(or more accurately, "dynamic schema“) Contains Documents. Indexable by one/more keys. Created on-the-fly when referenced for the first time. Capped Collections: Fixed size, older records get dropped after reaching the limit.
  • 16. Document Stored in a Collection. Can have _id key – works like Primary keys in MySQL. Supported Relationships – Embedded (or) References. . Document storage in BSON (Binary form of JSON)via GridFS (i.e. stores images, videos, anything...).
  • 17. Embedded Objects Documents can embed other documents For example: { name: 'Brad Majors', address: { street: 'Oak Terrace', city: 'Denton' } }
  • 18.
  • 19. Querying Query Expression Objects: MongoDB supports a number of query objects for fetching data. Simple query: db.users.find({}) More selective: db.users.find({'last_name': 'Smith'}) Query Options: Field Selection: // retrieve ssn field for documents where last_name == 'Smith': db.users.find({last_name: 'Smith'}, {'ssn': 1}); // retrieve all fields *except* the thumbnail field, for all documents: db.users.find({}, {thumbnail:0});
  • 20. Sorting: db.users.find({}).sort({last_name: 1}); // return all documents and sort by last name in ascending order Skip and Limit: db.users.find().skip(20).limit(10); //skips the first 20 last names, and limit our result set to 10 db.users.find({}, {}, 10, 20); // same as above, but less clear Cursors: Used to iteratively retrieve all the documents returned by the query. >var cur = db.example.find(); > cur.forEach( function(x) { print(tojson(x))}); {"n" : 1 , "_id" : "497ce96f395f2f052a494fd4"} {"n" : 2 , "_id" : "497ce971395f2f052a494fd5"}
  • 21. Queries Insert db.myCollection.save({key1: "value1", key2: "value2"}) db.myCollection.save({firstname: "Foo", lastname: "Bar", address: {Street: "Foo", City: "Bar"}}) Read db.myCollection.find({lastname: "Meier"}, {firstname: true}).limit(10).skip(20) Update db.myCollection.update({id: 123}, {$set : {a : 4}}) Delete db.myCollection.remove({firstname: "Hans"});
  • 22. Advanced Queries Conditional operators • db.things.find({j : {$lt: 3}}); More operators: $lte, $gt, $gte $all, $any, $or, $and, $size & more Nested query • db.persons.insert(firstname: "Meier", loves: ['apple', 'orange', 'tomato']) • db.persons.find($or: [{loves: 'apple'}, {loves: 'orange'}]) JavaScript expression • db.myCollection.find( { $where: "this.a > 3" } );
  • 23. Query examples -usingembeddeddocuments&referenceddocuments Exact match an entire embedded object db.users.find( {address: {street: 'Oak Terrace', city: 'Denton'}} ) Dot-notation for a partial match db.users.find( {"address.city": 'Denton'} ) Allows us to deep, nested queries db.order.find( { shipping: { carrier: "usps" } } ); here shipping is an embedded document (object)
  • 24.
  • 25. Schema Design There is no predefined schema, dynamic schema. Application creates an ad-hoc schema with the objects it creates The schema is implicit in the queries Collections to represent the top-level classes Less normalization, more embedding
  • 27. MongoDB: It depicts the Shapes object stored in the form of JSON type document. This eliminates the storage space involved in creating columns and rows.
  • 28. Better Schema Design: Embedding Collection for posts Embed comments, author name post = { author: 'Michael Arrington', text: 'This is a pretty awesome post.', comments: [ 'Whatever this post.', 'I agree, lame!' ] }
  • 29. Schema Design Limitations No referential integrity High degree of denormalization means updating something in many places instead of one Lack of predefined schema is a double-edged sword Should have model in the application Objects within a collection can be completely inconsistent in their fields
  • 30. MongoDB Admin UI's Some UI's are available as separate community projects and are listed below. Some are focused on administration, while some focus on data viewing. Tools MongoExplorer MongoVUE PHPMoAdmin Meclipse Commercial Database Master Data Viewers mongs
  • 31. MongoVue: MongoVUE is a .NET GUI for MongoDB. It is elegant and highly usable GUI interface to work with MongoDB. It helps in managing web-scale data.
  • 32. Database Master Database Master from Nucleon Software Features: Tree view for dbs and collections Create/Drop indexes Server/DB stats
  • 33.
  • 34. Sharding Data is split up into chunks, each is assigned to a shard Shard: Single server or Replica set Config Servers: Store meta data about chunks and data location Mongos: Routes requests in a transparent way
  • 35.
  • 37. Some Cool features Geo-spatial Indexes for Geo-spatial queries. $near, $within_distance, Bound queries (circle, box) GridFS Stores Large Binary Files. Map/Reduce GROUP BY in SQL, map/reduce in MongoDB.
  • 38. Map/Reduce Data processing . It has some basic aggregation capabilities. Parallelized for working with large sets of data. mapReduce takes a map function, a reduce function and an output directive. Map Funtion : A master node takes an input. Splits it into smaller sections. Sends it to the associated nodes. These nodes may perform the same operation in turn to send those smaller section of input to other nodes. It process the problem (taken as input) and sends it back to the Master Node.
  • 39. Reduce Function: The master node aggregates those results to find the output. Then, we can use the mapReduce command against some hits collection by: > db.hits.mapReduce(map, reduce,{out: {inline:1}}); We could instead specify {out: 'hit_stats'} and have the results stored in the hit_stats collections: > db.hits.mapReduce(map, reduce,{out:'hit_stats'}); > db.hit_stats.find(); Map/Reduce contd...
  • 40.
  • 41. Mongodb Security Trusted environment is default. The current version of Mongo supports only basic security. We can authenticate a username and password in the context of a particular database. Once authenticated, a normal user has full read and write access to the database. $ ./mongo > use admin > db.auth("someAdminUser", password) .
  • 42. Mongodb Security contd.. If there are no admin users, we should first create an administrator user for the entire db server process. This user is stored under the special admin database. One may access the database from the localhost interface without authenticating. Thus, from the server running the database configure an administrative user: $ ./mongo > use admin > db.addUser("theadmin", "anadminpassword")
  • 43. Mongodb Security contd.. Now, let's configure a "regular" user for another database. > use projectx > db.addUser("joe", "passwordForJoe") Finally, let's add a readonly user. > use projectx > db.addUser("guest", "passwordForGuest", true)
  • 44. Cool uses Data Warehouse Mongo understands JSON natively Very powerful for analysis Query a bunch of data from web service Import into mongo (mongoimport –f filename.json) Harmonyapp.com Large rails app for building websites (kind of a CMS) Hardcore debugging Spit out large amounts of data
  • 45.
  • 46. Applications RDBMS replacement for Web Applications. Semi-structured Content Management. Real-time Analytics & High-Speed Logging. Caching and High Scalability. Web 2.0, Media, SAAS, Gaming HealthCare, Finance, Telecom, Government
  • 47. Some Companies using MongoDB in Production
  • 48.
  • 49. Conclusion MongoDB is fast. It achieves high performance. It bridges the gap between traditional RDBMS at one end and Key-Value pair search engines at the other end. Document model is simple but powerful. Advanced features like map/reduce, geospatial indexing etc. are very compelling. Very rapid development, open source & surprisingly great drivers for most languages.
  • 50. Bibliography The required information is extracted from the following websites:- www.wikipedia.org http://www.mongodb.org/ http://www.10gen.com/ http://www.w3resource.com/mongodb/introduction- mongodb.php http://www.jaspersoft.com/bigdata#bigdata-middle-tab-5 http://blog.michaelckennedy.net/2010/04/29/mongodb-vs-sql- server-2008-performance-showdown/ http://blog.iprofs.nl/2011/11/25/is-mongodb-a-good- alternative-to-rdbms-databases-like-oracle-and-mysql/