SlideShare a Scribd company logo
{{
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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Alison B. Lowndes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 

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