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

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
PostgresOpen
 

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

SALMAN UPDATED CV NEW
SALMAN UPDATED CV NEWSALMAN UPDATED CV NEW
SALMAN UPDATED CV NEW
SALMAN KHAN
 

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

database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
Leerpiny Makouach
 

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

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
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
AnaAcapella
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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)
 
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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
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
 
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...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
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...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 

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