SlideShare a Scribd company logo
1 of 15
Download to read offline
{{
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
 
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
 
MongoDB & PHP
MongoDB & PHPMongoDB & PHP
MongoDB & PHP
 

Recently uploaded

A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 

Recently uploaded (20)

A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
How Tech Giants Cut Corners to Harvest Data for A.I.
How Tech Giants Cut Corners to Harvest Data for A.I.How Tech Giants Cut Corners to Harvest Data for A.I.
How Tech Giants Cut Corners to Harvest Data for A.I.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 

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