SlideShare a Scribd company logo
1 of 4
Create Database
===============
Syntax
use DATABASE_NAME
Ex
use mydb
Verification
show dbs
--------------------------------------------------------------------------------
-----------------------------------------------------
Drop Database
=============
Syntax:
db.dropDatabase()
Ex:
use mydb
db.dropDatabase()
Verification:
show dbs
--------------------------------------------------------------------------------
-----------------------------------------------------
Create/Insert Collection
========================
Syntax:
db.createCollection(name, options)
Ex:
use test
db.createCollection("mycollection")
db.createCollection("mycol", { capped : true, autoIndexID : true, size :
6142800, max : 10000 } )
db.tutorialspoint.insert({"name" : "tutorialspoint"})
Verification:
show collections
--------------------------------------------------------------------------------
-----------------------------------------------------
Drop Collection
===============
Syntax:
db.COLLECTION_NAME.drop()
Verification:
use mydb
show collections
Ex:
db.mycollection.drop()
Verification:
show collections
--------------------------------------------------------------------------------
-----------------------------------------------------
Insert Document
===============
Syntax:
db.COLLECTION_NAME.insert(document)
Ex:
db.mycol.insert({
_id: ObjectId(7df78ad8902c),
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
})
db.post.insert([
{
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
},
{
title: 'NoSQL Database',
description: 'NoSQL database doesn't have tables',
by: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 20,
comments: [
{
user:'user1',
message: 'My first comment',
dateCreated: new Date(2013,11,10,2,35),
like: 0
}
]
}
])
Verification:
--------------------------------------------------------------------------------
-----------------------------------------------------
Query Document
==============
Syntax:
db.COLLECTION_NAME.find()
db.COLLECTION_NAME.find().pretty()
db.COLLECTION_NAME.find({key1:value1, key2:value2}).pretty()
db.COLLECTION_NAME.find(
{
$or: [
{key1: value1}, {key2:value2}
]
}
).pretty()
Ex:
db.mycol.find().pretty()
db.mycol.find({"by":"tutorials point","title": "MongoDB Overview"}).pretty()
db.mycol.find({$or:[{"by":"tutorials point"},{"title": "MongoDB
Overview"}]}).pretty()
db.mycol.find({"likes": {$gt:10}, $or: [{"by": "tutorials point"},{"title":
"MongoDB Overview"}]}).pretty()
--------------------------------------------------------------------------------
-----------------------------------------------------
Update values in Document
=========================
Syntax:
db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)
Ex:
db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB
Tutorial'}})
Verification:
db.mycol.find()
--------------------------------------------------------------------------------
-----------------------------------------------------
Replace Document
================
Syntax:
db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA})
Ex:
db.mycol.save(
{
"_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point New
Topic", "by":"Tutorials Point"
}
)
Verification:
db.mycol.find()
--------------------------------------------------------------------------------
-----------------------------------------------------
Delete Document
===============
Syntax:
db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)
db.COLLECTION_NAME.remove()
Ex:
db.mycol.remove({'title':'MongoDB Overview'})
db.mycol.remove()
Verification:
db.mycol.find()
--------------------------------------------------------------------------------
-----------------------------------------------------
Projection
==========
Syntax:
db.COLLECTION_NAME.find({},{KEY:1})
Ex:
db.mycol.find({},{"title":1,_id:0})
--------------------------------------------------------------------------------
-----------------------------------------------------
Limit Records
=============
Syntax:
db.COLLECTION_NAME.find().limit(NUMBER)
db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)
Ex:
db.mycol.find({},{"title":1,_id:0}).limit(2)
db.mycol.find({},{"title":1,_id:0}).limit(1).skip(1)
--------------------------------------------------------------------------------
-----------------------------------------------------
Sort Records
============
Syntax:
db.COLLECTION_NAME.find().sort({KEY:1})
Ex:
db.mycol.find({},{"title":1,_id:0}).sort({"title":-1})
--------------------------------------------------------------------------------
-----------------------------------------------------
Indexing
========
Syntax:
db.COLLECTION_NAME.ensureIndex({KEY:1})
Ex:
db.mycol.ensureIndex({"title":1})
db.mycol.ensureIndex({"title":1,"description":-1})
--------------------------------------------------------------------------------
-----------------------------------------------------
Aggregation
===========
Syntax:
db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)
Ex:
db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}])
--------------------------------------------------------------------------------
-----------------------------------------------------
Create Backup/Restore
=====================
Syntax:
mongodump
mongorestore

More Related Content

What's hot

PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan DirectivesFranck Pachot
 
Redo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12cRedo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12cDebasish Nayak
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
The Essential postgresql.conf
The Essential postgresql.confThe Essential postgresql.conf
The Essential postgresql.confRobert Treat
 
Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7I Goo Lee
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Alexey Lesovsky
 
[PGDay.Seoul 2020] PostgreSQL 13 New Features
[PGDay.Seoul 2020] PostgreSQL 13 New Features[PGDay.Seoul 2020] PostgreSQL 13 New Features
[PGDay.Seoul 2020] PostgreSQL 13 New Featureshyeongchae lee
 
Restore MySQL database from mysqlbackup
Restore MySQL database from mysqlbackup Restore MySQL database from mysqlbackup
Restore MySQL database from mysqlbackup AllDatabaseSolutions
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenPostgresOpen
 

What's hot (18)

PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
 
Quick reference for curl
Quick reference for curlQuick reference for curl
Quick reference for curl
 
Redo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12cRedo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12c
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
The Essential postgresql.conf
The Essential postgresql.confThe Essential postgresql.conf
The Essential postgresql.conf
 
Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Sas online training
Sas online trainingSas online training
Sas online training
 
Free toolsinstall
Free toolsinstallFree toolsinstall
Free toolsinstall
 
Backups
BackupsBackups
Backups
 
[PGDay.Seoul 2020] PostgreSQL 13 New Features
[PGDay.Seoul 2020] PostgreSQL 13 New Features[PGDay.Seoul 2020] PostgreSQL 13 New Features
[PGDay.Seoul 2020] PostgreSQL 13 New Features
 
Restore MySQL database from mysqlbackup
Restore MySQL database from mysqlbackup Restore MySQL database from mysqlbackup
Restore MySQL database from mysqlbackup
 
Db2 imp commands
Db2 imp commandsDb2 imp commands
Db2 imp commands
 
Hadoop Performance comparison
Hadoop Performance comparisonHadoop Performance comparison
Hadoop Performance comparison
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 

Viewers also liked

Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop iACT Global
 
SALMAN UPDATED CV NEW
SALMAN UPDATED CV NEWSALMAN UPDATED CV NEW
SALMAN UPDATED CV NEWSALMAN KHAN
 
Fms solutii externalizare mng ro
Fms solutii externalizare mng roFms solutii externalizare mng ro
Fms solutii externalizare mng roRazvan CALOTA
 
06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы
06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы
06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавыAnastasiyaF
 
book Desert storm has it ended christ in islam ahmed dedat pdf
book Desert storm has it ended christ in islam ahmed dedat pdfbook Desert storm has it ended christ in islam ahmed dedat pdf
book Desert storm has it ended christ in islam ahmed dedat pdfslideshare account
 
Stock Repurchases aka Share Buybacks for US Firms
Stock Repurchases aka Share Buybacks for US FirmsStock Repurchases aka Share Buybacks for US Firms
Stock Repurchases aka Share Buybacks for US FirmsPranav Ghai
 
A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com...
 A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com... A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com...
A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com...nexgentechnology
 
Thiqar kploat 27 10 2016
Thiqar kploat 27 10 2016Thiqar kploat 27 10 2016
Thiqar kploat 27 10 2016Nour Elbader
 
01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі
01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі
01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыіAnastasiyaF
 
23. Хрысціянства на заходніх землях Старажытнай Русі
23. Хрысціянства на заходніх землях Старажытнай Русі23. Хрысціянства на заходніх землях Старажытнай Русі
23. Хрысціянства на заходніх землях Старажытнай РусіAnastasiyaF
 

Viewers also liked (14)

Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop
 
Poster images
Poster images Poster images
Poster images
 
SALMAN UPDATED CV NEW
SALMAN UPDATED CV NEWSALMAN UPDATED CV NEW
SALMAN UPDATED CV NEW
 
Scarab4 slideshare
Scarab4 slideshareScarab4 slideshare
Scarab4 slideshare
 
Fms solutii externalizare mng ro
Fms solutii externalizare mng roFms solutii externalizare mng ro
Fms solutii externalizare mng ro
 
06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы
06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы
06. Усходнеславянскія плямёны на тэрыторыі Беларусі. На шляху да дзяржавы
 
book Desert storm has it ended christ in islam ahmed dedat pdf
book Desert storm has it ended christ in islam ahmed dedat pdfbook Desert storm has it ended christ in islam ahmed dedat pdf
book Desert storm has it ended christ in islam ahmed dedat pdf
 
El Vareliano
El VarelianoEl Vareliano
El Vareliano
 
DBHS55-PSR-P_LR
DBHS55-PSR-P_LRDBHS55-PSR-P_LR
DBHS55-PSR-P_LR
 
Stock Repurchases aka Share Buybacks for US Firms
Stock Repurchases aka Share Buybacks for US FirmsStock Repurchases aka Share Buybacks for US Firms
Stock Repurchases aka Share Buybacks for US Firms
 
A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com...
 A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com... A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com...
A Profit Maximization Scheme with Guaranteed Quality of Service in Cloud Com...
 
Thiqar kploat 27 10 2016
Thiqar kploat 27 10 2016Thiqar kploat 27 10 2016
Thiqar kploat 27 10 2016
 
01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі
01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі
01. Становішча ў Беларусі напярэдадні Кастрычніцкай рэвалюцыі
 
23. Хрысціянства на заходніх землях Старажытнай Русі
23. Хрысціянства на заходніх землях Старажытнай Русі23. Хрысціянства на заходніх землях Старажытнай Русі
23. Хрысціянства на заходніх землях Старажытнай Русі
 

Similar to Quick reference for mongo shell commands

Pluggable database tutorial
Pluggable database tutorialPluggable database tutorial
Pluggable database tutorialOsama Mustafa
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Michael Schwern
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-noteLeerpiny Makouach
 
Pluggable database tutorial 2
Pluggable database tutorial 2Pluggable database tutorial 2
Pluggable database tutorial 2Osama Mustafa
 
Oracle data guard configuration in 12c
Oracle data guard configuration in 12cOracle data guard configuration in 12c
Oracle data guard configuration in 12cuzzal basak
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Database decommission process
Database decommission processDatabase decommission process
Database decommission processK Kumar Guduru
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
Drizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationDrizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationAndrew Hutchings
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioningSource Ministry
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 

Similar to Quick reference for mongo shell commands (20)

Pluggable database tutorial
Pluggable database tutorialPluggable database tutorial
Pluggable database tutorial
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 
Pluggable database tutorial 2
Pluggable database tutorial 2Pluggable database tutorial 2
Pluggable database tutorial 2
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
Oracle data guard configuration in 12c
Oracle data guard configuration in 12cOracle data guard configuration in 12c
Oracle data guard configuration in 12c
 
PHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHPPHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHP
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Database decommission process
Database decommission processDatabase decommission process
Database decommission process
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Drizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationDrizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free Migration
 
Quick reference for Grafana
Quick reference for GrafanaQuick reference for Grafana
Quick reference for Grafana
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Percona toolkit
Percona toolkitPercona toolkit
Percona toolkit
 
Sqlite perl
Sqlite perlSqlite perl
Sqlite perl
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Csql Cache Presentation
Csql Cache PresentationCsql Cache Presentation
Csql Cache Presentation
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

Quick reference for mongo shell commands

  • 1. Create Database =============== Syntax use DATABASE_NAME Ex use mydb Verification show dbs -------------------------------------------------------------------------------- ----------------------------------------------------- Drop Database ============= Syntax: db.dropDatabase() Ex: use mydb db.dropDatabase() Verification: show dbs -------------------------------------------------------------------------------- ----------------------------------------------------- Create/Insert Collection ======================== Syntax: db.createCollection(name, options) Ex: use test db.createCollection("mycollection") db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } ) db.tutorialspoint.insert({"name" : "tutorialspoint"}) Verification: show collections -------------------------------------------------------------------------------- ----------------------------------------------------- Drop Collection =============== Syntax: db.COLLECTION_NAME.drop() Verification: use mydb show collections Ex: db.mycollection.drop() Verification: show collections -------------------------------------------------------------------------------- ----------------------------------------------------- Insert Document =============== Syntax: db.COLLECTION_NAME.insert(document) Ex: db.mycol.insert({ _id: ObjectId(7df78ad8902c), title: 'MongoDB Overview', description: 'MongoDB is no sql database', by: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 }) db.post.insert([
  • 2. { title: 'MongoDB Overview', description: 'MongoDB is no sql database', by: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 }, { title: 'NoSQL Database', description: 'NoSQL database doesn't have tables', by: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 20, comments: [ { user:'user1', message: 'My first comment', dateCreated: new Date(2013,11,10,2,35), like: 0 } ] } ]) Verification: -------------------------------------------------------------------------------- ----------------------------------------------------- Query Document ============== Syntax: db.COLLECTION_NAME.find() db.COLLECTION_NAME.find().pretty() db.COLLECTION_NAME.find({key1:value1, key2:value2}).pretty() db.COLLECTION_NAME.find( { $or: [ {key1: value1}, {key2:value2} ] } ).pretty() Ex: db.mycol.find().pretty() db.mycol.find({"by":"tutorials point","title": "MongoDB Overview"}).pretty() db.mycol.find({$or:[{"by":"tutorials point"},{"title": "MongoDB Overview"}]}).pretty() db.mycol.find({"likes": {$gt:10}, $or: [{"by": "tutorials point"},{"title": "MongoDB Overview"}]}).pretty() -------------------------------------------------------------------------------- ----------------------------------------------------- Update values in Document ========================= Syntax: db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA) Ex: db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB Tutorial'}}) Verification: db.mycol.find() -------------------------------------------------------------------------------- ----------------------------------------------------- Replace Document ================ Syntax:
  • 3. db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA}) Ex: db.mycol.save( { "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point New Topic", "by":"Tutorials Point" } ) Verification: db.mycol.find() -------------------------------------------------------------------------------- ----------------------------------------------------- Delete Document =============== Syntax: db.COLLECTION_NAME.remove(DELLETION_CRITTERIA) db.COLLECTION_NAME.remove() Ex: db.mycol.remove({'title':'MongoDB Overview'}) db.mycol.remove() Verification: db.mycol.find() -------------------------------------------------------------------------------- ----------------------------------------------------- Projection ========== Syntax: db.COLLECTION_NAME.find({},{KEY:1}) Ex: db.mycol.find({},{"title":1,_id:0}) -------------------------------------------------------------------------------- ----------------------------------------------------- Limit Records ============= Syntax: db.COLLECTION_NAME.find().limit(NUMBER) db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER) Ex: db.mycol.find({},{"title":1,_id:0}).limit(2) db.mycol.find({},{"title":1,_id:0}).limit(1).skip(1) -------------------------------------------------------------------------------- ----------------------------------------------------- Sort Records ============ Syntax: db.COLLECTION_NAME.find().sort({KEY:1}) Ex: db.mycol.find({},{"title":1,_id:0}).sort({"title":-1}) -------------------------------------------------------------------------------- ----------------------------------------------------- Indexing ======== Syntax: db.COLLECTION_NAME.ensureIndex({KEY:1}) Ex: db.mycol.ensureIndex({"title":1}) db.mycol.ensureIndex({"title":1,"description":-1}) -------------------------------------------------------------------------------- ----------------------------------------------------- Aggregation =========== Syntax: db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION) Ex:
  • 4. db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}]) -------------------------------------------------------------------------------- ----------------------------------------------------- Create Backup/Restore ===================== Syntax: mongodump mongorestore