SlideShare a Scribd company logo
1 of 38
A. D. Patel Institute Of Technology
Big Data and Analytics [2171607] : A. Y. 2019-20
Installing MongoDB , Querying through MongoDB &
MongoDB through JavaScript Shell
Prepared By :
Dhruv V. Shah (160010116053)
B.E. (IT) Sem - VII
Guided By :
Dr. Narendra Chauhan
(Head Of IT Dept. , ADIT)
Department Of Information Technology
A.D. Patel Institute Of Technology (ADIT)
New Vallabh Vidyanagar , Anand , Gujarat
1
Outline
 Introduction
 Why Use MongoDB ? & What is MongoDB great for?
 MongoDB : CAP Approach.
 Steps for MongoDB Installation
 MongoDB CRUD Operations
 MongoDB through JavaScript Shell
 References
2
Introduction
 What is MongoDB ?
 MongoDB is a general purpose, document-based, distributed database built for modern
application developers and for the cloud era.
 MongoDB is a document database, which means it stores data in JSON-like documents (called
BSON [Binary JavaScript Object Notation]).
 It falls under the category of a NoSQL database.
 MongoDB is
 Scalable High-Performance Open-source, Document-orientated database.
 Built for Speed.
 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.
3
Cont..
4
Fig 1. Terms of SQL & MongoDB
 Key points of MongoDB
1. Develop Faster
2. Deploy Easier
3. Scale Bigger
 In MongoDB , Fields contains set of key & value pair.
Why use MongoDB ?
 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.
5
What is MongoDB great for?
 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
MongoDB : CAP Approach
 Focus on Consistency and Partitiontolerance.
 Consistency
 all replicas contain the same version of the data.
 Availability
 system remains operationalon failing nodes.
 Partition Tolerance
 multiple entry points
 system remains operationalon system split
6
C
A P
CAP Theorem:
 satisfying all three at the same time
is impossible.
Steps for MongoDB Installation
7
Link For MongoDB : https://www.mongodb.com/download-center/enterprise
8
Cont..
9
Cont..
10
Cont..
11
Cont..
12
Cont..
13
Cont..
14
Cont..
15
 Suppose in my laptop MongoDB location is as below :
 Path : C:Program FilesMongoDBServer4.2bin
 In window, we can write this path as follow :cd C:Program FilesMongoDBServer4.2bin
and then after write mongo.exe then press enter to start the mongoDB.
Cont..
Fig. MongoDB Terminal
MongoDB CRUD Operations
16
Fig. MongoDB Operations
 Create or insert operations add new documents to a collection.
 If the collection does not currently exist, insert/save operations will create the collection.
 MongoDB provides the following methods to insert documents into a collection :
1) db.collection_name.insertOne() .
2) db.collection_name.insertMany() .
 Other than this two methods one another method also available for creating collections which is
written below:
 db.createCollection(“collection_name”) .
17
Create Operations
db.collection_name.insertOne()
 This command is use for inserting one document at a time in the collection.
18
 For Eg. :
db.collection_name.insertMany()
 This command is use for inserting multiple document at a time in the collection.
19
 For Eg. :
db.createCollection(“collection_name”)
 This command is use for creating collection.
20
 For Eg. :
 Read operations retrieves documents from a collection; i.e. queries a collection for documents.
 MongoDB provides the following methods to read documents from a collection:
1) db.collection_name.find() .
 If we execute the above query for read or display the collection data then it is not produce output
in human readable form or we can say that it produces output in linear sequence.
 If we want to display the output in humane readable or well formatted way then write below
command:
 db.collection_name.find().pretty() .
21
Read Operations
Cont...
22
 For Eg. :
 Update operations modify existing documents in a collection.
 MongoDB provides the following methods to update documents of a collection:
1) db.collection_name.updateOne() :
 This command is use for updating or modifying document value or add a new key
attribute into the existing collection at a time only one updated.
2) db.collection_name.updateMany() :
 This command is use for updating or modifying document value or add a new key
attribute into the existing collection at a time multiple updated.
3) db.collection_name.replaceOne() :
 This method actually work by replacing entire existing document with new
document. It is not use for modifying the existing document.
 In MongoDB, update operations target a single collection. All write operations in MongoDB are
atomic on the level of a single document.
23
Update Operations
Cont...
24
 For Eg. :
1) db.collection_name.updateOne() :
Cont...
25
 For Eg. :
2) db.collection_name.updateMany() :
Cont...
26
 For Eg. :
3) db.collection_name.replaceOne() :
 Delete operations remove documents from a collection.
 MongoDB provides the following methods to delete documents of a collection:
1) db.collection_name.deleteOne() :
 This command is use for removing or deleting document from the collection at a
time only one deleted.
2) db.collection_name.deleteMany() :
 This command is use for removing or deleting document from the collection at a
time many deleted.
 In MongoDB, delete operations target a single collection.
 All write operations in MongoDB are atomic on the level of a single document.
27
Delete Operations
Cont...
28
 For Eg. :
1) db.collection_name.deleteOne() :
Cont...
29
 For Eg. :
2) db.collection_name.deleteMany() :
 The MongoDB shell is an interactive JavaScript shell.
 As such, it provides the capability to use JavaScript code directly in the shell or executed as a
standalone JavaScript file.
 You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or
perform administrative operation.
30
MongoDB through JavaScript Shell
 OPENING NEW CONNECTIONS
 From the mongo shell or from a JavaScript file, you can instantiate database connections
using the Mongo() constructor:
 new Mongo()
 new Mongo(<host>)
 new Mongo(<host: port>)
 Consider the following example that instantiates a new connection to the MongoDB instance
running on localhost on the default port and sets the global db variable to myDatabase using
the getDB() method:
 conn = new Mongo();
 db = conn.getDB("myDatabase");
31
Cont...
 DIFFERENCE BETWEEN SHELL HELPERS AND JS EQUIVALENTS
32
Cont...
 db.adminCommand()
 db.adminCommand() runs commands against the admin database regardless of the database
context in which it runs.
 EXAMPLE: The following example uses db.adminCommand() to execute the
renameCollection administrative database command to rename the orders collection in the
test database to orders-2016.
db.adminCommand (
{
renameCollection: "test.orders",
to: "test.orders-2016“
}
)
33
Cont...
34
Cont...
 db.getCollectionName()
 Returns an array containing the names of all collections and views in the current database, or
if running with access control, the names of the collections according to user’s privilege.
 EXAMPLE: The following returns the names of all collections in the records database:
use records
db.getCollectionNames()
 The method returns the names of the collections in an array:
[ "employees", "products", "mylogs", "system.indexes" ]
35
Cont...
 db.getUsers()
 Returns information for all the users in the database.
 EXAMPLE:
To view all users for the current database who have SCRAM-SHA-256 credentials:
db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })
36
Cont...
 Scripting
 From the system prompt, use mongo to evaluate JavaScript.
1) --eval option :
 Use the --eval option to mongo to pass the shell a JavaScript fragment, as in the
following:
 mongo test --eval "printjson(db.getCollectionNames())"
2) Execute a JavaScript file :
 You can specify a .js file to the mongo shell, and mongo will execute the JavaScript
directly. Consider the following example:
 mongo localhost:27017/test myjsfile.js
 This operation executes the myjsfile.js script in a mongo shell that connects to the test
database on the mongod instance accessible via the localhost interface on port 27017.
3) Load a JavaScript :
 This function loads and executes the myjstest.js file.
 You can execute a .js file from within the mongo shell, using the load() function, as in the
following:
 load("myjstest.js")
References
37
1) https://www.javatpoint.com/mongodb-tutorial
2) https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/
3) https://docs.mongodb.com/manual/crud/
4) https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
38

More Related Content

What's hot

Tms training
Tms trainingTms training
Tms trainingChi Lee
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Dinesh Neupane
 
Data Management 2: Conquering Data Proliferation
Data Management 2: Conquering Data ProliferationData Management 2: Conquering Data Proliferation
Data Management 2: Conquering Data ProliferationMongoDB
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBWildan Maulana
 
introduction to Mongodb
introduction to Mongodbintroduction to Mongodb
introduction to MongodbASIT
 
The Ring programming language version 1.6 book - Part 30 of 189
The Ring programming language version 1.6 book - Part 30 of 189The Ring programming language version 1.6 book - Part 30 of 189
The Ring programming language version 1.6 book - Part 30 of 189Mahmoud Samir Fayed
 
2011 mongo FR - scaling with mongodb
2011 mongo FR - scaling with mongodb2011 mongo FR - scaling with mongodb
2011 mongo FR - scaling with mongodbantoinegirbal
 
New Features in Apache Pinot
New Features in Apache PinotNew Features in Apache Pinot
New Features in Apache PinotSiddharth Teotia
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo dbDaeMyung Kang
 
introtomongodb
introtomongodbintrotomongodb
introtomongodbsaikiran
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDBMongoDB
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDBTim Callaghan
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introductionantoinegirbal
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBBehrouz Bakhtiari
 
Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2rusersla
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)MongoDB
 

What's hot (20)

Tms training
Tms trainingTms training
Tms training
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
 
Data Management 2: Conquering Data Proliferation
Data Management 2: Conquering Data ProliferationData Management 2: Conquering Data Proliferation
Data Management 2: Conquering Data Proliferation
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDB
 
introduction to Mongodb
introduction to Mongodbintroduction to Mongodb
introduction to Mongodb
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
The Ring programming language version 1.6 book - Part 30 of 189
The Ring programming language version 1.6 book - Part 30 of 189The Ring programming language version 1.6 book - Part 30 of 189
The Ring programming language version 1.6 book - Part 30 of 189
 
2011 mongo FR - scaling with mongodb
2011 mongo FR - scaling with mongodb2011 mongo FR - scaling with mongodb
2011 mongo FR - scaling with mongodb
 
New Features in Apache Pinot
New Features in Apache PinotNew Features in Apache Pinot
New Features in Apache Pinot
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
 
introtomongodb
introtomongodbintrotomongodb
introtomongodb
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
 
Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
 

Similar to MongoDB installation,CRUD operation & JavaScript shell

MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductiondinkar thakur
 
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
 
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
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchDaniel M. Farrell
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling Sachin Bhosale
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentationHyphen Call
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEANTroy Miles
 
MongoDB - How to model and extract your data
MongoDB - How to model and extract your dataMongoDB - How to model and extract your data
MongoDB - How to model and extract your dataFrancesco Lo Franco
 
Sekilas PHP + mongoDB
Sekilas PHP + mongoDBSekilas PHP + mongoDB
Sekilas PHP + mongoDBHadi Ariawan
 
MongoDB .local London 2019: Fast Machine Learning Development with MongoDB
MongoDB .local London 2019: Fast Machine Learning Development with MongoDBMongoDB .local London 2019: Fast Machine Learning Development with MongoDB
MongoDB .local London 2019: Fast Machine Learning Development with MongoDBLisa Roth, PMP
 

Similar to MongoDB installation,CRUD operation & JavaScript shell (20)

Mongodb By Vipin
Mongodb By VipinMongodb By Vipin
Mongodb By Vipin
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_search
 
Mdb dn 2016_06_query_primer
Mdb dn 2016_06_query_primerMdb dn 2016_06_query_primer
Mdb dn 2016_06_query_primer
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling MongoDB Introduction and Data Modelling
MongoDB Introduction and Data Modelling
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
 
Mongodb Introduction
Mongodb Introduction Mongodb Introduction
Mongodb Introduction
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
 
Mongo db
Mongo dbMongo db
Mongo db
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
MongoDB - How to model and extract your data
MongoDB - How to model and extract your dataMongoDB - How to model and extract your data
MongoDB - How to model and extract your data
 
Mongodb
MongodbMongodb
Mongodb
 
Sekilas PHP + mongoDB
Sekilas PHP + mongoDBSekilas PHP + mongoDB
Sekilas PHP + mongoDB
 
MongoDB .local London 2019: Fast Machine Learning Development with MongoDB
MongoDB .local London 2019: Fast Machine Learning Development with MongoDBMongoDB .local London 2019: Fast Machine Learning Development with MongoDB
MongoDB .local London 2019: Fast Machine Learning Development with MongoDB
 

More from ShahDhruv21

Semantic net in AI
Semantic net in AISemantic net in AI
Semantic net in AIShahDhruv21
 
Error Detection & Error Correction Codes
Error Detection & Error Correction CodesError Detection & Error Correction Codes
Error Detection & Error Correction CodesShahDhruv21
 
Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)ShahDhruv21
 
Data Mining in Health Care
Data Mining in Health CareData Mining in Health Care
Data Mining in Health CareShahDhruv21
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs ShahDhruv21
 
2D Transformation
2D Transformation2D Transformation
2D TransformationShahDhruv21
 
Topological Sorting
Topological SortingTopological Sorting
Topological SortingShahDhruv21
 
Pyramid Vector Quantization
Pyramid Vector QuantizationPyramid Vector Quantization
Pyramid Vector QuantizationShahDhruv21
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
WaterFall Model & Spiral Mode
WaterFall Model & Spiral ModeWaterFall Model & Spiral Mode
WaterFall Model & Spiral ModeShahDhruv21
 

More from ShahDhruv21 (12)

Semantic net in AI
Semantic net in AISemantic net in AI
Semantic net in AI
 
Error Detection & Error Correction Codes
Error Detection & Error Correction CodesError Detection & Error Correction Codes
Error Detection & Error Correction Codes
 
Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)
 
Data Mining in Health Care
Data Mining in Health CareData Mining in Health Care
Data Mining in Health Care
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Interpreter
InterpreterInterpreter
Interpreter
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Pyramid Vector Quantization
Pyramid Vector QuantizationPyramid Vector Quantization
Pyramid Vector Quantization
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
WaterFall Model & Spiral Mode
WaterFall Model & Spiral ModeWaterFall Model & Spiral Mode
WaterFall Model & Spiral Mode
 

Recently uploaded

Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 

Recently uploaded (20)

Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 

MongoDB installation,CRUD operation & JavaScript shell

  • 1. A. D. Patel Institute Of Technology Big Data and Analytics [2171607] : A. Y. 2019-20 Installing MongoDB , Querying through MongoDB & MongoDB through JavaScript Shell Prepared By : Dhruv V. Shah (160010116053) B.E. (IT) Sem - VII Guided By : Dr. Narendra Chauhan (Head Of IT Dept. , ADIT) Department Of Information Technology A.D. Patel Institute Of Technology (ADIT) New Vallabh Vidyanagar , Anand , Gujarat 1
  • 2. Outline  Introduction  Why Use MongoDB ? & What is MongoDB great for?  MongoDB : CAP Approach.  Steps for MongoDB Installation  MongoDB CRUD Operations  MongoDB through JavaScript Shell  References 2
  • 3. Introduction  What is MongoDB ?  MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.  MongoDB is a document database, which means it stores data in JSON-like documents (called BSON [Binary JavaScript Object Notation]).  It falls under the category of a NoSQL database.  MongoDB is  Scalable High-Performance Open-source, Document-orientated database.  Built for Speed.  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. 3
  • 4. Cont.. 4 Fig 1. Terms of SQL & MongoDB  Key points of MongoDB 1. Develop Faster 2. Deploy Easier 3. Scale Bigger  In MongoDB , Fields contains set of key & value pair.
  • 5. Why use MongoDB ?  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. 5 What is MongoDB great for?  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
  • 6. MongoDB : CAP Approach  Focus on Consistency and Partitiontolerance.  Consistency  all replicas contain the same version of the data.  Availability  system remains operationalon failing nodes.  Partition Tolerance  multiple entry points  system remains operationalon system split 6 C A P CAP Theorem:  satisfying all three at the same time is impossible.
  • 7. Steps for MongoDB Installation 7 Link For MongoDB : https://www.mongodb.com/download-center/enterprise
  • 15. 15  Suppose in my laptop MongoDB location is as below :  Path : C:Program FilesMongoDBServer4.2bin  In window, we can write this path as follow :cd C:Program FilesMongoDBServer4.2bin and then after write mongo.exe then press enter to start the mongoDB. Cont.. Fig. MongoDB Terminal
  • 16. MongoDB CRUD Operations 16 Fig. MongoDB Operations
  • 17.  Create or insert operations add new documents to a collection.  If the collection does not currently exist, insert/save operations will create the collection.  MongoDB provides the following methods to insert documents into a collection : 1) db.collection_name.insertOne() . 2) db.collection_name.insertMany() .  Other than this two methods one another method also available for creating collections which is written below:  db.createCollection(“collection_name”) . 17 Create Operations
  • 18. db.collection_name.insertOne()  This command is use for inserting one document at a time in the collection. 18  For Eg. :
  • 19. db.collection_name.insertMany()  This command is use for inserting multiple document at a time in the collection. 19  For Eg. :
  • 20. db.createCollection(“collection_name”)  This command is use for creating collection. 20  For Eg. :
  • 21.  Read operations retrieves documents from a collection; i.e. queries a collection for documents.  MongoDB provides the following methods to read documents from a collection: 1) db.collection_name.find() .  If we execute the above query for read or display the collection data then it is not produce output in human readable form or we can say that it produces output in linear sequence.  If we want to display the output in humane readable or well formatted way then write below command:  db.collection_name.find().pretty() . 21 Read Operations
  • 23.  Update operations modify existing documents in a collection.  MongoDB provides the following methods to update documents of a collection: 1) db.collection_name.updateOne() :  This command is use for updating or modifying document value or add a new key attribute into the existing collection at a time only one updated. 2) db.collection_name.updateMany() :  This command is use for updating or modifying document value or add a new key attribute into the existing collection at a time multiple updated. 3) db.collection_name.replaceOne() :  This method actually work by replacing entire existing document with new document. It is not use for modifying the existing document.  In MongoDB, update operations target a single collection. All write operations in MongoDB are atomic on the level of a single document. 23 Update Operations
  • 24. Cont... 24  For Eg. : 1) db.collection_name.updateOne() :
  • 25. Cont... 25  For Eg. : 2) db.collection_name.updateMany() :
  • 26. Cont... 26  For Eg. : 3) db.collection_name.replaceOne() :
  • 27.  Delete operations remove documents from a collection.  MongoDB provides the following methods to delete documents of a collection: 1) db.collection_name.deleteOne() :  This command is use for removing or deleting document from the collection at a time only one deleted. 2) db.collection_name.deleteMany() :  This command is use for removing or deleting document from the collection at a time many deleted.  In MongoDB, delete operations target a single collection.  All write operations in MongoDB are atomic on the level of a single document. 27 Delete Operations
  • 28. Cont... 28  For Eg. : 1) db.collection_name.deleteOne() :
  • 29. Cont... 29  For Eg. : 2) db.collection_name.deleteMany() :
  • 30.  The MongoDB shell is an interactive JavaScript shell.  As such, it provides the capability to use JavaScript code directly in the shell or executed as a standalone JavaScript file.  You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or perform administrative operation. 30 MongoDB through JavaScript Shell
  • 31.  OPENING NEW CONNECTIONS  From the mongo shell or from a JavaScript file, you can instantiate database connections using the Mongo() constructor:  new Mongo()  new Mongo(<host>)  new Mongo(<host: port>)  Consider the following example that instantiates a new connection to the MongoDB instance running on localhost on the default port and sets the global db variable to myDatabase using the getDB() method:  conn = new Mongo();  db = conn.getDB("myDatabase"); 31 Cont...
  • 32.  DIFFERENCE BETWEEN SHELL HELPERS AND JS EQUIVALENTS 32 Cont...
  • 33.  db.adminCommand()  db.adminCommand() runs commands against the admin database regardless of the database context in which it runs.  EXAMPLE: The following example uses db.adminCommand() to execute the renameCollection administrative database command to rename the orders collection in the test database to orders-2016. db.adminCommand ( { renameCollection: "test.orders", to: "test.orders-2016“ } ) 33 Cont...
  • 34. 34 Cont...  db.getCollectionName()  Returns an array containing the names of all collections and views in the current database, or if running with access control, the names of the collections according to user’s privilege.  EXAMPLE: The following returns the names of all collections in the records database: use records db.getCollectionNames()  The method returns the names of the collections in an array: [ "employees", "products", "mylogs", "system.indexes" ]
  • 35. 35 Cont...  db.getUsers()  Returns information for all the users in the database.  EXAMPLE: To view all users for the current database who have SCRAM-SHA-256 credentials: db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })
  • 36. 36 Cont...  Scripting  From the system prompt, use mongo to evaluate JavaScript. 1) --eval option :  Use the --eval option to mongo to pass the shell a JavaScript fragment, as in the following:  mongo test --eval "printjson(db.getCollectionNames())" 2) Execute a JavaScript file :  You can specify a .js file to the mongo shell, and mongo will execute the JavaScript directly. Consider the following example:  mongo localhost:27017/test myjsfile.js  This operation executes the myjsfile.js script in a mongo shell that connects to the test database on the mongod instance accessible via the localhost interface on port 27017. 3) Load a JavaScript :  This function loads and executes the myjstest.js file.  You can execute a .js file from within the mongo shell, using the load() function, as in the following:  load("myjstest.js")
  • 37. References 37 1) https://www.javatpoint.com/mongodb-tutorial 2) https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/ 3) https://docs.mongodb.com/manual/crud/ 4) https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
  • 38. 38