A
Seminar Presentation
on
MongoDB
Submitted in partial fulfillment for the award of degree of
BACHELOR OF TECHNOLOGY
In
Computer Science & Engineering
Submitted To: Submitted By:
Ms. Pooja Sharma
Ujjawal Mathur
Ms. Nimisha Bhatt
(16EGJCS809)
Department of Computer Science & Engineering
GLOBAL INSTITUTE OF TECHNOLOGY
JAIPUR (RAJASTHAN)-302022
SESSION: 2019-20
1
Agenda
• Problems with RDBMS
• What is MongoDB
• Performance of SQL and MongoDB
• Comparison between SQL and MongoDB
• CURD operation in MongoDB
• Where clause commands
Why MongoDB why not MySQL?
• Before we understand what MongoDB is we need to
understand issues with traditional RDBMS.
1. Scalability
❖ Difficult to scale millions of
millions of data.
❖ Data stored in multiple
tables (relationship) it is
difficult to scale.
2. Flexibility
❖ Fixed data structure
therefore not easy to make
modifications
to data structure
❖ You need to spend hours
and hours on designing the
database before development
❖ In Agile projects database
requires constant restructuring
3. Performance
❖ Data is generally stored
across multiple tables. Joins
have huge performance impact
as it requires lot of CPU and
resources
❖ Need to install and configure
complex caching mechanism to
make it faster
MongoDB vs SQL performance chart
What is MongoDB?
❖ It is a NoSQL database called (Document database)
❖ It stores data in flexible JSON-like document.
^ Easy to develop REST API in JSON
❖ It is highly scalable and flexible database
How MongoDB looks when compared
to RDBMS ?
{
“first_name” : “Joe”,
first_name last_name email
“last_name” : “Satana”,
“email” : “
[email protected]”
Joe Satana
[email protected] },
{
Bob Michel
[email protected] “first_name” : “Bob”,
“last_name” : “Michel”,
“email” : “
[email protected]”
}
]
Comparison between SQL and MongoDB
SQL Server MongoDB
Database Database
Table Collection
Index Index
Row Document
Column Field
Joining Linking & Embedding
Where to use MongoDB?
• Big Data
• Content Management and Delivery
• Mobile and Social Infrastructure
• User Data Management
• Data Hub
MongoDB commands
mongo Enter the MongoDB client
show dbs List all database. Should have at least on record to display the db in list.
db Display active database name
Show the database name, number of collection and documents in the
db.stats()
database, etc.
use db_name To switch / create database
db.dropDatabase( Drop database
)
Collections — Tables in MongoDB is called as collections
To create a collection
db.createcollection(name of collection)
To drop a collection
db.collection_name.drop()
CRUD
■ Create
db.collection.insert( <document> )
db.collection.insert({'author':'Bob','title':'Introduction to mysql','article':'mongodb is open source database'})
■ Read
db.collection.find( <query>, <projection> ) db.collection. find({' author' :''Bob}
■ Update
db.collection.update( <query>, <update>, <options> )
db.collection.update({ 'author' :'Bob'},{'$set':{ 'title':'Introduction to mongoDB'}})
■ Delete
db.collection.remove( <query>, <justOne> ) db.collection.remove({'author':'Bob'})
CRUD Example
> db.user.find ()
> db.user.insert({
{
first: "_id" : ObjectId("51..."),
"John", "first" : "John",
last : "last" : "Doe",
"Doe", "age" : 39
}
age:39
> db.user.update(
{"Jd" : ObjectId("51...")},
{ > db.user.remove({
$set: { age:
40, salary:
"first": /J
7000} } })
Where conditions
Operation Syntax Example RDBMS Equivalent
Equality {<key>:<value>} db.posts.find({"by":"tutorials point"}).pretty() where by = 'tutorials point'
Less Than {<key>:{$lt:<value>}} db.posts.find({"likes":{$lt:50}}).pretty0 where likes < 50
Less Than Equals {<key>:{$lte:<value>}} db.posts.find({"likes":{$lte:50}}).pretty0 where likes <= 50
Greater Than {<key>:{$gt:<value>}} db.posts.find({"likes":{$gt:50}}).pretty() where likes > 50
Greater Than
{<key>:{$gte:<value>}} db.posts.find({"likes":{$gte:50}}).pretty() where likes >= 50
Equals
Like {<key>:{'$regex':<value>}} db.posts.find({"title": {'$regex': 'How'} }) where title like '%How%'
Reference
• https://docs.mongodb.com/manual/reference
Conclusion
MongoDB, with its flexible schema, distributed deployment, aggregation and low latency is
typically suited for the following kind of applications:
■ Content Management
■ Inventory Management
■ Game Development
■ Social Media Storage
■ Database for sensor streams
Thank you