SlideShare une entreprise Scribd logo
1  sur  15
{{
MongoDB CRUDMongoDB CRUD
Using NoSQLUsing NoSQL
-Darshan J-Darshan J
 Installation
 Connection with MongoDB
 Insert in MongoDB
 Fetching data from MongoDB
 The “Where” clause
 Greater than, less than , equals ,and, or operators
 Update and Upsert in MongoDB
 Removing documents in collections.
 Q & A
AgendaAgenda
 Are you good in Copy Paste?Are you good in Copy Paste?
 Get the binaries of your OS flavor fromGet the binaries of your OS flavor from https://https://
www.mongodb.org/downloadswww.mongodb.org/downloads
 Unzip the file copy theUnzip the file copy the binbin folder and paste in desiredfolder and paste in desired
location.location.
 Your MongoDB is ready to launch.Your MongoDB is ready to launch.
InstallationInstallation
 MongoDB starts dataserver in mongod daemon , youMongoDB starts dataserver in mongod daemon , you
should pass atleast data directory to start this binariesshould pass atleast data directory to start this binaries
 By default MongoDB starts with 27017 port anyhow youBy default MongoDB starts with 27017 port anyhow you
can change it usingcan change it using --port--port while starting the daemonwhile starting the daemon
 MongoDB have lot many startup parameter which youMongoDB have lot many startup parameter which you
can see incan see in mongod --helpmongod --help command.command.
Connecting to MongoDBConnecting to MongoDB
 CRUD stands for create read update and delete.CRUD stands for create read update and delete.
 MongoDB has flexible queries to operation on crud.MongoDB has flexible queries to operation on crud.
CRUDCRUD
 Insertion of document to mongoDB can be achievedInsertion of document to mongoDB can be achieved
through insert() method.through insert() method.
 mongoDB is freiendly as it will create database as well asmongoDB is freiendly as it will create database as well as
collection if you inserting the first document in thecollection if you inserting the first document in the
collection.collection.
 MongoDB will automatically insert _id field will beMongoDB will automatically insert _id field will be
automatically inserted for you, as a primary key if you doautomatically inserted for you, as a primary key if you do
not explicitly entered value in it.not explicitly entered value in it.
 Mongo is Schema less ( not a oracle term of schema)Mongo is Schema less ( not a oracle term of schema)
 No need to worry about the altering the table structureNo need to worry about the altering the table structure
INSERTINSERT
 Retrieving the data is main method in any DBMS,Retrieving the data is main method in any DBMS,
 You can retrieve data from MongoDB using find()You can retrieve data from MongoDB using find()
methodmethod
 Find method you can pass mainly 2 argumentsFind method you can pass mainly 2 arguments
 Condition of the data ( the Where clause)Condition of the data ( the Where clause)
 Selection of the field ( as a Boolean value)Selection of the field ( as a Boolean value)
 Sorting is separate method you can callSorting is separate method you can call
 By default find() method displays the output in oneBy default find() method displays the output in one
line you can make is readable using pretty()line you can make is readable using pretty()
method.method.
FetchingthedataFetchingthedata
 Where clause is the first argument in remove read andWhere clause is the first argument in remove read and
update method.update method.
 You can define your conditions in this clause.You can define your conditions in this clause.
 andand operation is easy whereoperation is easy where oror operator is some what trickyoperator is some what tricky
The WHERE clauseThe WHERE clause
SQL NoSQL
Select * from emp where
salary = 2000
Db.emp.find({salary:2000})
Select * from emp where
salary = 2000 and age =26
Db.emp.find({salary:2000,
age:26})
select * from emp where
salary = 2000 or age =26
db.emp.find({"$or":
[{"salary": 2000}, {"age":
26}]});
 When we query we really don’t need all the column output,When we query we really don’t need all the column output,
when we interested in only few it is better to get only thosewhen we interested in only few it is better to get only those
field which will also avoid the full collection scanfield which will also avoid the full collection scan
 In MongoDB this can be achieved in second argument ofIn MongoDB this can be achieved in second argument of
insert method.insert method.
 This takes Boolean value 1 as true 0 as false.This takes Boolean value 1 as true 0 as false.
 By default _id field will be 1 you can avoid displaying it byBy default _id field will be 1 you can avoid displaying it by
setting it 0.setting it 0.
Selecting fields to displaySelecting fields to display
SQL NoSQL
Select name from emp where salary =
2000
Db.emp.find({salary:2000},
{name:1,_id:0})
Select name,age from emp where
salary = 2000 and age =26
Db.emp.find({salary:2000, age:26}, },
{name:1,_id:0,age:1})
Comparison OperatorsComparison Operators
Select name from emp where sal > 10000
db.emp.find({sal : {$gt : 10000} })
Select name from emp where sal <= 50000
db.emp.find ( { sal : { $lte : 50000 } } )
Name Description
$gt Matches values that are greater than the value specified in the query.
$gte
Matches values that are greater than or equal to the value specified in
the query.
$lt Matches values that are less than the value specified in the query.
$lte
Matches values that are less than or equal to the value specified in the
query.
$ne Matches all values that are not equal to the value specified in the query.
$in Matches any of the values that exist in an array specified in the query.
$nin Matches values that do not exist in an array specified to the query.
Name Description
$or
Joins query clauses with a logical OR returns all documents that
match the conditions of either clause.
$and
Joins query clauses with a logical AND returns all documents that
match the conditions of both clauses.
$not
Inverts the effect of a query expression and returns documents that
do not match the query expression.
$nor
Joins query clauses with a logical NOR returns all documents that
fail to match both clauses.
Logical OperatorLogical Operator
Select * from emp where salary = 2000 and age =26
db.emp.find({$and : [{salary:2000}, {age:26}]})
select * from emp where salary = 2000 or age =26
db.emp.find({"$or": [{"salary": 2000}, {"age": 26}]});
 MongoDB's update()  methods are used to update
document into a collection. 
>db.COLLECTION_NAME.update(SELECTIOIN_CRITERI
A, UPDATED_DATA)
 Update emp set sal = 40000 where eid = a1115;
 Db.emp.update({eid:a1115},{$set:{sal:40000}})
 By default mongodb will update only single document, to
update multiple you need to set a paramter 'multi' to true.
 Db.emp.update({eid:a1115},{$set:{sal:40000}},{multi:true})
Updating the documentsUpdating the documents
 MongoDB's remove() method is used to remove document from
the collection. remove() method accepts two parameters. One is
deletion criteria and second is justOne flag
 deletion criteria : (Optional) deletion criteria according to documents
will be removed.
 justOne : (Optional) if set to true or 1, then remove only one
document.
 Delete from emp where eid = a1115
 Db.emp.remove({eid:a1115})
 If there are multiple records and you want to delete only first
record, then set justOneparameter in remove() method
 Db.emp.remove({eid:a1115},1)
 If you want to truncate whole table just don’t pass any selection
criteria.
 Db.emp.remove()
RemoveRemove
MongoDB crud
MongoDB crud

Contenu connexe

Tendances

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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNosh Petigara
 
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Anuj Jain
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010Eliot Horowitz
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLMongoDB
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
Moving from SQL Server to MongoDB
Moving from SQL Server to MongoDBMoving from SQL Server to MongoDB
Moving from SQL Server to MongoDBNick Court
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDBMongoDB
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBantoinegirbal
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBBehrouz Bakhtiari
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichNorberto Leite
 
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
 

Tendances (16)

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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Moving from SQL Server to MongoDB
Moving from SQL Server to MongoDBMoving from SQL Server to MongoDB
Moving from SQL Server to MongoDB
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days Munich
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
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
 

En vedette

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
Mongo db crud guide
Mongo db crud guideMongo db crud guide
Mongo db crud guideDeysi Gmarra
 
When to Use MongoDB
When to Use MongoDBWhen to Use MongoDB
When to Use MongoDBMongoDB
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Lucas Jellema
 
A Beginners Guide to noSQL
A Beginners Guide to noSQLA Beginners Guide to noSQL
A Beginners Guide to noSQLMike Crabb
 

En vedette (8)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db crud guide
Mongo db crud guideMongo db crud guide
Mongo db crud guide
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
When to Use MongoDB
When to Use MongoDBWhen to Use MongoDB
When to Use MongoDB
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
 
A Beginners Guide to noSQL
A Beginners Guide to noSQLA Beginners Guide to noSQL
A Beginners Guide to noSQL
 

Similaire à MongoDB crud (20)

MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Experiment no 2
Experiment no 2Experiment no 2
Experiment no 2
 
Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDB
 
Java beans
Java beansJava beans
Java beans
 
mongo.pptx
mongo.pptxmongo.pptx
mongo.pptx
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
MongoDB-presentation.pptx
MongoDB-presentation.pptxMongoDB-presentation.pptx
MongoDB-presentation.pptx
 
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
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 
Python database access
Python database accessPython database access
Python database access
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
 
Jdbc
JdbcJdbc
Jdbc
 
UNIT-1 MongoDB.pptx
UNIT-1 MongoDB.pptxUNIT-1 MongoDB.pptx
UNIT-1 MongoDB.pptx
 

Dernier

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Dernier (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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...
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

MongoDB crud

  • 1. {{ MongoDB CRUDMongoDB CRUD Using NoSQLUsing NoSQL -Darshan J-Darshan J
  • 2.  Installation  Connection with MongoDB  Insert in MongoDB  Fetching data from MongoDB  The “Where” clause  Greater than, less than , equals ,and, or operators  Update and Upsert in MongoDB  Removing documents in collections.  Q & A AgendaAgenda
  • 3.  Are you good in Copy Paste?Are you good in Copy Paste?  Get the binaries of your OS flavor fromGet the binaries of your OS flavor from https://https:// www.mongodb.org/downloadswww.mongodb.org/downloads  Unzip the file copy theUnzip the file copy the binbin folder and paste in desiredfolder and paste in desired location.location.  Your MongoDB is ready to launch.Your MongoDB is ready to launch. InstallationInstallation
  • 4.  MongoDB starts dataserver in mongod daemon , youMongoDB starts dataserver in mongod daemon , you should pass atleast data directory to start this binariesshould pass atleast data directory to start this binaries  By default MongoDB starts with 27017 port anyhow youBy default MongoDB starts with 27017 port anyhow you can change it usingcan change it using --port--port while starting the daemonwhile starting the daemon  MongoDB have lot many startup parameter which youMongoDB have lot many startup parameter which you can see incan see in mongod --helpmongod --help command.command. Connecting to MongoDBConnecting to MongoDB
  • 5.  CRUD stands for create read update and delete.CRUD stands for create read update and delete.  MongoDB has flexible queries to operation on crud.MongoDB has flexible queries to operation on crud. CRUDCRUD
  • 6.  Insertion of document to mongoDB can be achievedInsertion of document to mongoDB can be achieved through insert() method.through insert() method.  mongoDB is freiendly as it will create database as well asmongoDB is freiendly as it will create database as well as collection if you inserting the first document in thecollection if you inserting the first document in the collection.collection.  MongoDB will automatically insert _id field will beMongoDB will automatically insert _id field will be automatically inserted for you, as a primary key if you doautomatically inserted for you, as a primary key if you do not explicitly entered value in it.not explicitly entered value in it.  Mongo is Schema less ( not a oracle term of schema)Mongo is Schema less ( not a oracle term of schema)  No need to worry about the altering the table structureNo need to worry about the altering the table structure INSERTINSERT
  • 7.  Retrieving the data is main method in any DBMS,Retrieving the data is main method in any DBMS,  You can retrieve data from MongoDB using find()You can retrieve data from MongoDB using find() methodmethod  Find method you can pass mainly 2 argumentsFind method you can pass mainly 2 arguments  Condition of the data ( the Where clause)Condition of the data ( the Where clause)  Selection of the field ( as a Boolean value)Selection of the field ( as a Boolean value)  Sorting is separate method you can callSorting is separate method you can call  By default find() method displays the output in oneBy default find() method displays the output in one line you can make is readable using pretty()line you can make is readable using pretty() method.method. FetchingthedataFetchingthedata
  • 8.  Where clause is the first argument in remove read andWhere clause is the first argument in remove read and update method.update method.  You can define your conditions in this clause.You can define your conditions in this clause.  andand operation is easy whereoperation is easy where oror operator is some what trickyoperator is some what tricky The WHERE clauseThe WHERE clause SQL NoSQL Select * from emp where salary = 2000 Db.emp.find({salary:2000}) Select * from emp where salary = 2000 and age =26 Db.emp.find({salary:2000, age:26}) select * from emp where salary = 2000 or age =26 db.emp.find({"$or": [{"salary": 2000}, {"age": 26}]});
  • 9.  When we query we really don’t need all the column output,When we query we really don’t need all the column output, when we interested in only few it is better to get only thosewhen we interested in only few it is better to get only those field which will also avoid the full collection scanfield which will also avoid the full collection scan  In MongoDB this can be achieved in second argument ofIn MongoDB this can be achieved in second argument of insert method.insert method.  This takes Boolean value 1 as true 0 as false.This takes Boolean value 1 as true 0 as false.  By default _id field will be 1 you can avoid displaying it byBy default _id field will be 1 you can avoid displaying it by setting it 0.setting it 0. Selecting fields to displaySelecting fields to display SQL NoSQL Select name from emp where salary = 2000 Db.emp.find({salary:2000}, {name:1,_id:0}) Select name,age from emp where salary = 2000 and age =26 Db.emp.find({salary:2000, age:26}, }, {name:1,_id:0,age:1})
  • 10. Comparison OperatorsComparison Operators Select name from emp where sal > 10000 db.emp.find({sal : {$gt : 10000} }) Select name from emp where sal <= 50000 db.emp.find ( { sal : { $lte : 50000 } } ) Name Description $gt Matches values that are greater than the value specified in the query. $gte Matches values that are greater than or equal to the value specified in the query. $lt Matches values that are less than the value specified in the query. $lte Matches values that are less than or equal to the value specified in the query. $ne Matches all values that are not equal to the value specified in the query. $in Matches any of the values that exist in an array specified in the query. $nin Matches values that do not exist in an array specified to the query.
  • 11. Name Description $or Joins query clauses with a logical OR returns all documents that match the conditions of either clause. $and Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. $not Inverts the effect of a query expression and returns documents that do not match the query expression. $nor Joins query clauses with a logical NOR returns all documents that fail to match both clauses. Logical OperatorLogical Operator Select * from emp where salary = 2000 and age =26 db.emp.find({$and : [{salary:2000}, {age:26}]}) select * from emp where salary = 2000 or age =26 db.emp.find({"$or": [{"salary": 2000}, {"age": 26}]});
  • 12.  MongoDB's update()  methods are used to update document into a collection.  >db.COLLECTION_NAME.update(SELECTIOIN_CRITERI A, UPDATED_DATA)  Update emp set sal = 40000 where eid = a1115;  Db.emp.update({eid:a1115},{$set:{sal:40000}})  By default mongodb will update only single document, to update multiple you need to set a paramter 'multi' to true.  Db.emp.update({eid:a1115},{$set:{sal:40000}},{multi:true}) Updating the documentsUpdating the documents
  • 13.  MongoDB's remove() method is used to remove document from the collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag  deletion criteria : (Optional) deletion criteria according to documents will be removed.  justOne : (Optional) if set to true or 1, then remove only one document.  Delete from emp where eid = a1115  Db.emp.remove({eid:a1115})  If there are multiple records and you want to delete only first record, then set justOneparameter in remove() method  Db.emp.remove({eid:a1115},1)  If you want to truncate whole table just don’t pass any selection criteria.  Db.emp.remove() RemoveRemove