SlideShare a Scribd company logo
1 of 26
DOCUMENT BASED DATABASE
(MongoDB)
INTRODUCTION
• MongoDB is a schema-free document database written in C++ and
developed in an open-source project which is mainly driven by the
company 10gen Inc that also offers professional services around
MongoDB.
• the main goal of MongoDB is to close the gap between the fast and
highly scalable key-/value-stores and feature-rich traditional RDBMSs
relational database management systems.
• A database contains one or more collections consisting of documents.
• MongoDB is schema-free the documents within a collection may be
heterogeneous although the
• Once the first document is inserted into a database, a collection is
created automatically and the inserted document is added to this
collection.
It store data (which is in BSON – “Binary Serialized Document Notation” ) format
Advantage
Documents are independent units which makes performance better
(related data is read contiguously off disk) and makes it easier to
distribute data across multiple servers.
Application logic is easier to write. You don’t have to translate between
objects in your application and SQL queries, you can just turn the object model
directly into a document
Non-relational databases are highly scalable than the relational databases.
Non-relational databases process data faster than the relational databases
because they do not use ACID properties.
Non-relational databases are very flexible than the relational databases
because they are schemaless.
Disadvantage
Non-relational databases are less reliable than the relational databases
because they compromise reliability for performance.
Non-relational databases alsocompromise consistency for performance
In many non-relational databases security is lesser than relational databases
which is a major concern.
Like Mongodb and Cassandra both databases have lack of encryption for data
files, they have very weak authentication system, and very simple
authorization .
INSTALLATION
Step 1:- Download the latest production release of
MongoDB
Step 2:- Extract the downloaded archive.
• In Windows Explorer, find the MongoDB download file, typically in the
default Downloads directory.
• Extract the archive to C: by right clicking on the archive and selecting
Extract All and
Step 3:- Move the MongoDB directory to another
location.
• cd 
• move C:mongodb-win32-* C:mongodb
INSTALLATION(Cont…)
Step 4:- Set Up the Data Directory
Step 5:- Start MongoDB
The default location for the MongoDB data directory is C:datadb.
Create this folder using the Command Prompt. Go to the C: directory
and issue the following command sequence:
md data
md datadb
You can specify an alternate path for data files using the
C:mongodbbinmongod.exe --dbpath d:testmongodbdata
C:mongodbbinmongod.exe
This will start the main MongoDB database process. The waiting for
connections message in the console
output indicates that the mongod.exe process is running successfully.
INSTALLATION(Cont…)
Step 6:- Connect to MongoDB
Connect to MongoDB using the mongo.exe shell.
C:mongodbbinmongo.exe
The mongo.exe shell will connect to mongod.exe running on the
localhost interface and port 27017 by default.
BASIC OPERATIONS
Oper 1:- Related to Database
After starting the mongo shell your session will use the test database by
default.
• To show the name of current database -> DB
• To display list of database -> show dbs
• Switch to a new database named mydb or create new database -> use
mydb
NOTE:MongoDB will not permanently create a database until you
insert data into that database.
BASIC OPERATIONS(Cont…)
Oper 2:- Create a Collection and Insert Documents
• MongoDB uses dynamic schemas , you also need not specify the
structure of your documents before inserting them into the
collection.
• Insert documents in testDb collection
db.testDb.insert({x: 20})
db.testDb.insert({x: 25 , name: “mongo”})
• When you insert the first document, the mongod will create both a
mydb database and the testData collection.
• All MongoDB documents must have an _id field with a unique
value. These operations do not explicitly specify a value for the _id
field, so mongo creates a unique ObjectId value for the field before
inserting it into the collection.
BASIC OPERATIONS(Cont…)
• To show list of collections in current database -> show collections
• To show list of documents in collection -> db.testDb.find()
• Query for Specific Documents -> db.testDb.find({x: 18})
• Limit the Number of Documents in the Result Set ->
db.testDb.find().limit(3)
Oper 3:- Update an existing document
• In MongoDB, db.collection.update() and the db.collection.save() methods
perform update operations.
BASIC OPERATIONS(Cont…)
•By default, the db.collection.update() method updates a single document.
However, with the multi option, update() can update all documents in a collection
that match a query.
db.inventory.update(
{ type: "book", item : "journal" },
{ $set : { qty: 10 } },
{ upsert : true }
)
•Call the update() method with the upsert flag to create a new document if no
document matches the update’s query criteria.
BASIC OPERATIONS(Cont…)
By default, db.collection.remove() method removes all documents that match its
query. However, the method can accept a flag to limit the delete operation to a
single document.
Oper 4:- Delete an existing document
In MongoDB, db.collection.remove() method performs delete operations.
Oper 5:- Fetching documents from collections
BASIC OPERATIONS(Cont…)
BASIC OPERATIONS(Cont…)
Specifying an equality condition –> db.inventory.find( { type: "snacks" } )
Specify Conditions Using Query Operators -> db.inventory.find( { type: {
$in: [ 'food', 'snacks' ] } } )
Specify AND Conditions -> db.inventory.find( { type: 'food', price: { $lt:
9.95 } } )
Specify OR Conditions -> db.inventory.find({ $or: [{ qty: { $gt: 100 } },
{ price: { $lt: 9.95 } }]})
BASIC OPERATIONS(Cont…)
BASIC TERMS
• Queries in MongoDB return all fields in all matching documents by default. To
limit the amount of data that MongoDB sends to applications, include a projection
in the queries.
1:- Projection
Exclude One Field From a Result Set
db.records.find( { "user_id": { $lt: 42} }, { history: 0} )
NOTE : you cannot mix exclusive and inclusive projections , Except for excluding
the _id field in inclusive projections.
Return Two Fields and Exclude _id
db.records.find( { "user_id": { $lt: 42} }, { "_id": 0, "name": 1 , "email": 1 } )
2:- Cursors
In the mongo shell, the primary method for the read operation is the
db.collection.find() method. This method queries a collection and returns a
cursor to the returning documents.
SQL to MongoDB Mapping Chart
SQL Terms/Concepts MongoDB Terms/Concepts
database database
table collection
row document or BSON document
column field
index index
table joins embedded documents and linking
primary key
Specify any unique column or column
combination as primary key.
primary key
In MongoDB, the primary key is
automatically set to the_id field.
SQL to MongoDB Mapping Chart
SQL Schema Statements MongoDB Schema Statements
CREATE TABLE users ( id
MEDIUMINT NOT NULL
AUTO_INCREMENT, user_id
Varchar(30), age Number, status char(1),
PRIMARY KEY (id) )
Implicitly created on
first insert() operation. The primary
key _id is automatically added
if _id field is not specified.
db.users.insert( { user_id: "abc123",
age: 55, status: "A" } )
However, you can also explicitly create a
collection:
db.createCollection("users")
ALTER TABLE users ADD join_date
DATETIME
there is no structural alteration at the
collection level.
However, at the document
level, update() operations can add fields
to existing documents using
the $set operator.
1:- Create and alter
SQL to MongoDB Mapping Chart
SQL Schema Statements MongoDB Schema Statements
ALTER TABLE users DROP COLUMN
join_date
at the document
level, update() operations can remove
fields from documents using
the $unset operator.
db.users.update( { }, { $unset: {
join_date: "" } }, { multi: true } )
CREATE INDEX
idx_user_id_asc_age_desc ON
users(user_id, age DESC)
db.users.ensureIndex( { user_id: 1,
age: -1 } )
DROP TABLE users db.users.drop()
SQL to MongoDB Mapping Chart
2:- Insert
SQL INSERT Statements MongoDB insert() Statements
INSERT INTO users(user_id, age,
status) VALUES ("bcd001", 45, "A")
db.users.insert( { user_id: "bcd001",
age: 45, status: "A" } )
SQL to MongoDB Mapping Chart
3:- Select
SELECT user_id, status FROM users
db.users.find( { }, { user_id: 1, status: 1,
_id: 0 } )
SELECT * FROM users WHERE status
!= "A"
db.users.find( { status: { $ne: "A" } } )
SELECT * FROM users WHERE status
= "A" AND age = 50
db.users.find( { status: "A", age: 50 } )
SELECT * FROM users WHERE status
= "A" OR age = 50
db.users.find( { $or: [ { status: "A" } , {
age: 50 } ] } )
SELECT * FROM users WHERE age >
25 AND age <= 50
db.users.find( { age: { $gt: 25, $lte: 50 } } )
SQL to MongoDB Mapping Chart
3:- Select(Cont…)
SELECT * FROM users WHERE user_id
like "bc%"
db.users.find( { user_id: /^bc/ } )
SELECT * FROM users WHERE status =
"A" ORDER BY user_id DESC
db.users.find( { status: "A" } ).sort( {
user_id: -1 } )
SELECT COUNT(*) FROM users
db.users.count()
or
db.users.find().count()
SELECT COUNT(user_id) FROM users
db.users.count( { user_id: { $exists: true
} } )
or
db.users.find( { user_id: { $exists: true }
} ).count()
SQL to MongoDB Mapping Chart
3:- Select(Cont…)
SELECT DISTINCT(status) FROM users db.users.distinct( "status" )
SELECT * FROM users LIMIT 1
db.users.findOne()
or
db.users.find().limit(1)
SELECT * FROM users LIMIT 5 SKIP 10 db.users.find().limit(5).skip(10)
EXPLAIN SELECT * FROM users
WHERE status = "A"
db.users.find( { status: "A" } ).explain()
SQL to MongoDB Mapping Chart
4:- Update records
SQL Update Statements MongoDB update() Statements
UPDATE users SET status = "C"
WHERE age > 25
db.users.update( { age: { $gt: 25 } }, {
$set: { status: "C" } }, { multi: true } )
UPDATE users SET age = age + 3
WHERE status = "A"
db.users.update( { status: "A" } , {
$inc: { age: 3 } }, { multi: true } )
SQL to MongoDB Mapping Chart
5:- Delete records
SQL Delete Statements MongoDB remove() Statements
DELETE FROM users WHERE
status = "D"
db.users.remove( { status: "D" } )
DELETE FROM users db.users.remove({})
THANK YOU FOR READING
Dhaval M!5trY

More Related Content

What's hot

MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge shareMr Kyaing
 
The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185Mahmoud Samir Fayed
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.netNgeam Soly
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05Terry Yoast
 
ملخص تقنية تصميم صفحات الويب - الوحدة السادسة
ملخص تقنية تصميم صفحات الويب - الوحدة السادسةملخص تقنية تصميم صفحات الويب - الوحدة السادسة
ملخص تقنية تصميم صفحات الويب - الوحدة السادسةجامعة القدس المفتوحة
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile appsIvano Malavolta
 
The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210Mahmoud Samir Fayed
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329Douglas Duncan
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseMarco Gralike
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)Faysal Shaarani (MBA)
 

What's hot (19)

MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge share
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
ملخص تقنية تصميم صفحات الويب - الوحدة السادسة
ملخص تقنية تصميم صفحات الويب - الوحدة السادسةملخص تقنية تصميم صفحات الويب - الوحدة السادسة
ملخص تقنية تصميم صفحات الويب - الوحدة السادسة
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile apps
 
The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory Database
 
Ado.net
Ado.netAdo.net
Ado.net
 
Query Optimization in MongoDB
Query Optimization in MongoDBQuery Optimization in MongoDB
Query Optimization in MongoDB
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Ado.net
Ado.netAdo.net
Ado.net
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
 

Viewers also liked

MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)Mike Dirolf
 
Mango Database - Web Development
Mango Database - Web DevelopmentMango Database - Web Development
Mango Database - Web Developmentmssaman
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesignMongoDB APAC
 
Column oriented database
Column oriented databaseColumn oriented database
Column oriented databaseKanike Krishna
 
MongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesMongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesHadi Ariawan
 
Mongo db tutorials
Mongo db tutorialsMongo db tutorials
Mongo db tutorialsAnuj Jain
 
Administration (Eliot Horowitz)
Administration (Eliot Horowitz)Administration (Eliot Horowitz)
Administration (Eliot Horowitz)MongoSF
 
Shankar's mongo db presentation
Shankar's mongo db presentationShankar's mongo db presentation
Shankar's mongo db presentationShankar Kamble
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDBEnoch Joshua
 
Database Management system
Database Management systemDatabase Management system
Database Management systemVijay Thorat
 
NoSQL databases - An introduction
NoSQL databases - An introductionNoSQL databases - An introduction
NoSQL databases - An introductionPooyan Mehrparvar
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsSpringPeople
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 

Viewers also liked (20)

MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)
 
Mango Database - Web Development
Mango Database - Web DevelopmentMango Database - Web Development
Mango Database - Web Development
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
Column oriented database
Column oriented databaseColumn oriented database
Column oriented database
 
MongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesMongoDB Schema Design by Examples
MongoDB Schema Design by Examples
 
Mongo db tutorials
Mongo db tutorialsMongo db tutorials
Mongo db tutorials
 
Administration (Eliot Horowitz)
Administration (Eliot Horowitz)Administration (Eliot Horowitz)
Administration (Eliot Horowitz)
 
MediaGlu and Mongo DB
MediaGlu and Mongo DBMediaGlu and Mongo DB
MediaGlu and Mongo DB
 
Shankar's mongo db presentation
Shankar's mongo db presentationShankar's mongo db presentation
Shankar's mongo db presentation
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDB
 
NOSQL Overview
NOSQL OverviewNOSQL Overview
NOSQL Overview
 
Database Management system
Database Management systemDatabase Management system
Database Management system
 
NoSQL databases - An introduction
NoSQL databases - An introductionNoSQL databases - An introduction
NoSQL databases - An introduction
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
Mongo db
Mongo dbMongo db
Mongo db
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 

Similar to Mongo db basics

171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptxsukrithlal008
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRaghunath A
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptxSurya937648
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductiondinkar thakur
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverMongoDB
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Kai Zhao
 

Similar to Mongo db basics (20)

171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo db queries
Mongo db queriesMongo db queries
Mongo db queries
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
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
MongoDBMongoDB
MongoDB
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongodb By Vipin
Mongodb By VipinMongodb By Vipin
Mongodb By Vipin
 
Experiment no 2
Experiment no 2Experiment no 2
Experiment no 2
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
Mongo db
Mongo dbMongo db
Mongo db
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
MongoDB
MongoDBMongoDB
MongoDB
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Mongo db basics

  • 2. INTRODUCTION • MongoDB is a schema-free document database written in C++ and developed in an open-source project which is mainly driven by the company 10gen Inc that also offers professional services around MongoDB. • the main goal of MongoDB is to close the gap between the fast and highly scalable key-/value-stores and feature-rich traditional RDBMSs relational database management systems. • A database contains one or more collections consisting of documents. • MongoDB is schema-free the documents within a collection may be heterogeneous although the • Once the first document is inserted into a database, a collection is created automatically and the inserted document is added to this collection. It store data (which is in BSON – “Binary Serialized Document Notation” ) format
  • 3. Advantage Documents are independent units which makes performance better (related data is read contiguously off disk) and makes it easier to distribute data across multiple servers. Application logic is easier to write. You don’t have to translate between objects in your application and SQL queries, you can just turn the object model directly into a document Non-relational databases are highly scalable than the relational databases. Non-relational databases process data faster than the relational databases because they do not use ACID properties. Non-relational databases are very flexible than the relational databases because they are schemaless.
  • 4. Disadvantage Non-relational databases are less reliable than the relational databases because they compromise reliability for performance. Non-relational databases alsocompromise consistency for performance In many non-relational databases security is lesser than relational databases which is a major concern. Like Mongodb and Cassandra both databases have lack of encryption for data files, they have very weak authentication system, and very simple authorization .
  • 5. INSTALLATION Step 1:- Download the latest production release of MongoDB Step 2:- Extract the downloaded archive. • In Windows Explorer, find the MongoDB download file, typically in the default Downloads directory. • Extract the archive to C: by right clicking on the archive and selecting Extract All and Step 3:- Move the MongoDB directory to another location. • cd • move C:mongodb-win32-* C:mongodb
  • 6. INSTALLATION(Cont…) Step 4:- Set Up the Data Directory Step 5:- Start MongoDB The default location for the MongoDB data directory is C:datadb. Create this folder using the Command Prompt. Go to the C: directory and issue the following command sequence: md data md datadb You can specify an alternate path for data files using the C:mongodbbinmongod.exe --dbpath d:testmongodbdata C:mongodbbinmongod.exe This will start the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.
  • 7. INSTALLATION(Cont…) Step 6:- Connect to MongoDB Connect to MongoDB using the mongo.exe shell. C:mongodbbinmongo.exe The mongo.exe shell will connect to mongod.exe running on the localhost interface and port 27017 by default.
  • 8. BASIC OPERATIONS Oper 1:- Related to Database After starting the mongo shell your session will use the test database by default. • To show the name of current database -> DB • To display list of database -> show dbs • Switch to a new database named mydb or create new database -> use mydb NOTE:MongoDB will not permanently create a database until you insert data into that database.
  • 9. BASIC OPERATIONS(Cont…) Oper 2:- Create a Collection and Insert Documents • MongoDB uses dynamic schemas , you also need not specify the structure of your documents before inserting them into the collection. • Insert documents in testDb collection db.testDb.insert({x: 20}) db.testDb.insert({x: 25 , name: “mongo”}) • When you insert the first document, the mongod will create both a mydb database and the testData collection. • All MongoDB documents must have an _id field with a unique value. These operations do not explicitly specify a value for the _id field, so mongo creates a unique ObjectId value for the field before inserting it into the collection.
  • 10. BASIC OPERATIONS(Cont…) • To show list of collections in current database -> show collections • To show list of documents in collection -> db.testDb.find() • Query for Specific Documents -> db.testDb.find({x: 18}) • Limit the Number of Documents in the Result Set -> db.testDb.find().limit(3) Oper 3:- Update an existing document • In MongoDB, db.collection.update() and the db.collection.save() methods perform update operations.
  • 11. BASIC OPERATIONS(Cont…) •By default, the db.collection.update() method updates a single document. However, with the multi option, update() can update all documents in a collection that match a query. db.inventory.update( { type: "book", item : "journal" }, { $set : { qty: 10 } }, { upsert : true } ) •Call the update() method with the upsert flag to create a new document if no document matches the update’s query criteria.
  • 12. BASIC OPERATIONS(Cont…) By default, db.collection.remove() method removes all documents that match its query. However, the method can accept a flag to limit the delete operation to a single document. Oper 4:- Delete an existing document In MongoDB, db.collection.remove() method performs delete operations.
  • 13. Oper 5:- Fetching documents from collections BASIC OPERATIONS(Cont…)
  • 14. BASIC OPERATIONS(Cont…) Specifying an equality condition –> db.inventory.find( { type: "snacks" } ) Specify Conditions Using Query Operators -> db.inventory.find( { type: { $in: [ 'food', 'snacks' ] } } ) Specify AND Conditions -> db.inventory.find( { type: 'food', price: { $lt: 9.95 } } ) Specify OR Conditions -> db.inventory.find({ $or: [{ qty: { $gt: 100 } }, { price: { $lt: 9.95 } }]})
  • 16. BASIC TERMS • Queries in MongoDB return all fields in all matching documents by default. To limit the amount of data that MongoDB sends to applications, include a projection in the queries. 1:- Projection Exclude One Field From a Result Set db.records.find( { "user_id": { $lt: 42} }, { history: 0} ) NOTE : you cannot mix exclusive and inclusive projections , Except for excluding the _id field in inclusive projections. Return Two Fields and Exclude _id db.records.find( { "user_id": { $lt: 42} }, { "_id": 0, "name": 1 , "email": 1 } ) 2:- Cursors In the mongo shell, the primary method for the read operation is the db.collection.find() method. This method queries a collection and returns a cursor to the returning documents.
  • 17. SQL to MongoDB Mapping Chart SQL Terms/Concepts MongoDB Terms/Concepts database database table collection row document or BSON document column field index index table joins embedded documents and linking primary key Specify any unique column or column combination as primary key. primary key In MongoDB, the primary key is automatically set to the_id field.
  • 18. SQL to MongoDB Mapping Chart SQL Schema Statements MongoDB Schema Statements CREATE TABLE users ( id MEDIUMINT NOT NULL AUTO_INCREMENT, user_id Varchar(30), age Number, status char(1), PRIMARY KEY (id) ) Implicitly created on first insert() operation. The primary key _id is automatically added if _id field is not specified. db.users.insert( { user_id: "abc123", age: 55, status: "A" } ) However, you can also explicitly create a collection: db.createCollection("users") ALTER TABLE users ADD join_date DATETIME there is no structural alteration at the collection level. However, at the document level, update() operations can add fields to existing documents using the $set operator. 1:- Create and alter
  • 19. SQL to MongoDB Mapping Chart SQL Schema Statements MongoDB Schema Statements ALTER TABLE users DROP COLUMN join_date at the document level, update() operations can remove fields from documents using the $unset operator. db.users.update( { }, { $unset: { join_date: "" } }, { multi: true } ) CREATE INDEX idx_user_id_asc_age_desc ON users(user_id, age DESC) db.users.ensureIndex( { user_id: 1, age: -1 } ) DROP TABLE users db.users.drop()
  • 20. SQL to MongoDB Mapping Chart 2:- Insert SQL INSERT Statements MongoDB insert() Statements INSERT INTO users(user_id, age, status) VALUES ("bcd001", 45, "A") db.users.insert( { user_id: "bcd001", age: 45, status: "A" } )
  • 21. SQL to MongoDB Mapping Chart 3:- Select SELECT user_id, status FROM users db.users.find( { }, { user_id: 1, status: 1, _id: 0 } ) SELECT * FROM users WHERE status != "A" db.users.find( { status: { $ne: "A" } } ) SELECT * FROM users WHERE status = "A" AND age = 50 db.users.find( { status: "A", age: 50 } ) SELECT * FROM users WHERE status = "A" OR age = 50 db.users.find( { $or: [ { status: "A" } , { age: 50 } ] } ) SELECT * FROM users WHERE age > 25 AND age <= 50 db.users.find( { age: { $gt: 25, $lte: 50 } } )
  • 22. SQL to MongoDB Mapping Chart 3:- Select(Cont…) SELECT * FROM users WHERE user_id like "bc%" db.users.find( { user_id: /^bc/ } ) SELECT * FROM users WHERE status = "A" ORDER BY user_id DESC db.users.find( { status: "A" } ).sort( { user_id: -1 } ) SELECT COUNT(*) FROM users db.users.count() or db.users.find().count() SELECT COUNT(user_id) FROM users db.users.count( { user_id: { $exists: true } } ) or db.users.find( { user_id: { $exists: true } } ).count()
  • 23. SQL to MongoDB Mapping Chart 3:- Select(Cont…) SELECT DISTINCT(status) FROM users db.users.distinct( "status" ) SELECT * FROM users LIMIT 1 db.users.findOne() or db.users.find().limit(1) SELECT * FROM users LIMIT 5 SKIP 10 db.users.find().limit(5).skip(10) EXPLAIN SELECT * FROM users WHERE status = "A" db.users.find( { status: "A" } ).explain()
  • 24. SQL to MongoDB Mapping Chart 4:- Update records SQL Update Statements MongoDB update() Statements UPDATE users SET status = "C" WHERE age > 25 db.users.update( { age: { $gt: 25 } }, { $set: { status: "C" } }, { multi: true } ) UPDATE users SET age = age + 3 WHERE status = "A" db.users.update( { status: "A" } , { $inc: { age: 3 } }, { multi: true } )
  • 25. SQL to MongoDB Mapping Chart 5:- Delete records SQL Delete Statements MongoDB remove() Statements DELETE FROM users WHERE status = "D" db.users.remove( { status: "D" } ) DELETE FROM users db.users.remove({})
  • 26. THANK YOU FOR READING Dhaval M!5trY