SlideShare a Scribd company logo
1 of 3
Download to read offline
Practical No:11
Problem Statement: Implement aggregation and indexing with suitable example
using MongoDB.
*Index*
> use prac11
switched to db prac11
> db.stud.insert({_id:1,rollno:28,name:"Shail",dept:10});
> db.stud.insert({_id:2,rollno:26,name:"Shivesh",dept:10});
> db.stud.find();
{ "_id" : 1, "rollno" : 28, "name" : "Shail", "dept" : 10 }
{ "_id" : 2, "rollno" : 26, "name" : "Shivesh", "dept" : 10 }
> db.stud.insert({_id:3,rollno:22,name:"Alquama",dept:11});
> db.stud.insert({_id:4,rollno:33,name:"Swapnil",dept:11});
>
> db.stud.find().pretty();
{ "_id" : 1, "rollno" : 28, "name" : "Shail", "dept" : 10 }
{ "_id" : 2, "rollno" : 26, "name" : "Shivesh", "dept" : 10 }
{ "_id" : 3, "rollno" : 22, "name" : "Alquama", "dept" : 11 }
{ "_id" : 4, "rollno" : 33, "name" : "Swapnil", "dept" : 11 }
db.stud.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "prac11.stud",
"name" : "_id_"
}
]
db.stud.ensureIndex({name:1});
> db.stud.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "prac11.stud",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"name" : 1
},
"ns" : "prac11.stud",
"name" : "name_1"
}
db.stud.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "prac11.stud",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"name" : 1
},
"ns" : "prac11.stud",
"name" : "name_1"
},
{
"v" : 1,
"key" : {
"rollno" : 1
},
"unique" : true,
"ns" : "prac11.stud",
"name" : "rollno_1"
}
db.system.indexes.find();
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.stud", "name" : "_id_" }
{ "v" : 1, "key" : { "name" : 1 }, "ns" : "prac11.stud", "name" : "name_1" }
{ "v" : 1, "key" : { "rollno" : 1 }, "unique" : true, "ns" : "prac11.stud",
"name" : "rollno_1" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.item", "name" : "_id_" }
--------------------------------------------------------------------------------
------------------------
*Aggergation*
db.item.insert({Customer:'a',Name:"Mouse",Quantity:3,Price:200});
db.item.insert({Customer:'a',Name:"Keyboard",Quantity:5,Price:800});
> db.item.insert({Customer:'b',Name:"Mouse",Quantity:3,Price:500});
> db.item.insert({Customer:'a',Name:"Keyboard",Quantity:4,Price:2000});
> db.item.find().pretty();
{
"_id" : ObjectId("5d8f128237dc2e143b51bde5"),
"Customer" : "a",
"Name" : "Mouse",
"Quantity" : 3,
"Price" : 200
}
{
"_id" : ObjectId("5d8f12a637dc2e143b51bde6"),
"Customer" : "a",
"Name" : "Keyboard",
"Quantity" : 5,
"Price" : 800
}
{
"_id" : ObjectId("5d8f12be37dc2e143b51bde7"),
"Customer" : "b",
"Name" : "Mouse",
"Quantity" : 3,
"Price" : 500
}
{
"_id" : ObjectId("5d8f12da37dc2e143b51bde8"),
"Customer" : "a",
"Name" : "Keyboard",
"Quantity" : 4,
"Price" : 2000
}
> db.item.aggregate([{$group:{_id:"Name",total:{$sum:1}}}]);
{ "result" : [ { "_id" : "Name", "total" : 4 } ], "ok" : 1 }
aggregation and indexing with suitable example using MongoDB.

More Related Content

What's hot

List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionarynitamhaske
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
halstead software science measures
halstead software science measureshalstead software science measures
halstead software science measuresDeepti Pillai
 
Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)Timbal Mayank
 
Html heading
Html headingHtml heading
Html headingsaichii27
 
Kotlin scope functions
Kotlin scope functionsKotlin scope functions
Kotlin scope functionsWaheed Nazir
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in pythonKarin Lagesen
 
Deep drive into rust programming language
Deep drive into rust programming languageDeep drive into rust programming language
Deep drive into rust programming languageVigneshwer Dhinakaran
 
LINUX:Control statements in shell programming
LINUX:Control statements in shell programmingLINUX:Control statements in shell programming
LINUX:Control statements in shell programmingbhatvijetha
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)CLOSEST PAIR (Final)
CLOSEST PAIR (Final)Aruneel Das
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionarySoba Arjun
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and SetsNicole Ryan
 

What's hot (20)

MySQL Functions
MySQL FunctionsMySQL Functions
MySQL Functions
 
Php forms
Php formsPhp forms
Php forms
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
halstead software science measures
halstead software science measureshalstead software science measures
halstead software science measures
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Html heading
Html headingHtml heading
Html heading
 
Kotlin scope functions
Kotlin scope functionsKotlin scope functions
Kotlin scope functions
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Operators php
Operators phpOperators php
Operators php
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in python
 
N queen problem
N queen problemN queen problem
N queen problem
 
Primality
PrimalityPrimality
Primality
 
Deep drive into rust programming language
Deep drive into rust programming languageDeep drive into rust programming language
Deep drive into rust programming language
 
LINUX:Control statements in shell programming
LINUX:Control statements in shell programmingLINUX:Control statements in shell programming
LINUX:Control statements in shell programming
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)CLOSEST PAIR (Final)
CLOSEST PAIR (Final)
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
 

More from bhavesh lande

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 bhavesh lande
 
information control and Security system
information control and Security systeminformation control and Security system
information control and Security systembhavesh lande
 
information technology and infrastructures choices
information technology and  infrastructures choicesinformation technology and  infrastructures choices
information technology and infrastructures choicesbhavesh lande
 
ethical issues,social issues
 ethical issues,social issues ethical issues,social issues
ethical issues,social issuesbhavesh lande
 
managing inforamation system
managing inforamation systemmanaging inforamation system
managing inforamation systembhavesh lande
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governancebhavesh lande
 
organisations and information systems
organisations and  information systemsorganisations and  information systems
organisations and information systemsbhavesh lande
 
IT stratergy and digital goods
IT stratergy and digital goodsIT stratergy and digital goods
IT stratergy and digital goodsbhavesh lande
 
Implement Mapreduce with suitable example using MongoDB.
 Implement Mapreduce with suitable example using MongoDB. Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.bhavesh lande
 
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
 Unnamed PL/SQL code block: Use of Control structure and Exception handling i... Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...bhavesh lande
 
database application using SQL DML statements: all types of Join, Sub-Query ...
 database application using SQL DML statements: all types of Join, Sub-Query ... database application using SQL DML statements: all types of Join, Sub-Query ...
database application using SQL DML statements: all types of Join, Sub-Query ...bhavesh lande
 
database application using SQL DML statements: Insert, Select, Update, Delet...
 database application using SQL DML statements: Insert, Select, Update, Delet... database application using SQL DML statements: Insert, Select, Update, Delet...
database application using SQL DML statements: Insert, Select, Update, Delet...bhavesh lande
 
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
 Design and Develop SQL DDL statements which demonstrate the use of SQL objec... Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...bhavesh lande
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of pythonbhavesh lande
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data sciencebhavesh lande
 
data scientists and their role
data scientists and their roledata scientists and their role
data scientists and their rolebhavesh lande
 

More from bhavesh lande (20)

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019
 
information control and Security system
information control and Security systeminformation control and Security system
information control and Security system
 
information technology and infrastructures choices
information technology and  infrastructures choicesinformation technology and  infrastructures choices
information technology and infrastructures choices
 
ethical issues,social issues
 ethical issues,social issues ethical issues,social issues
ethical issues,social issues
 
managing inforamation system
managing inforamation systemmanaging inforamation system
managing inforamation system
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance
 
IT and innovations
 IT and  innovations  IT and  innovations
IT and innovations
 
organisations and information systems
organisations and  information systemsorganisations and  information systems
organisations and information systems
 
IT stratergy and digital goods
IT stratergy and digital goodsIT stratergy and digital goods
IT stratergy and digital goods
 
Implement Mapreduce with suitable example using MongoDB.
 Implement Mapreduce with suitable example using MongoDB. Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.
 
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
 Unnamed PL/SQL code block: Use of Control structure and Exception handling i... Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
 
database application using SQL DML statements: all types of Join, Sub-Query ...
 database application using SQL DML statements: all types of Join, Sub-Query ... database application using SQL DML statements: all types of Join, Sub-Query ...
database application using SQL DML statements: all types of Join, Sub-Query ...
 
database application using SQL DML statements: Insert, Select, Update, Delet...
 database application using SQL DML statements: Insert, Select, Update, Delet... database application using SQL DML statements: Insert, Select, Update, Delet...
database application using SQL DML statements: Insert, Select, Update, Delet...
 
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
 Design and Develop SQL DDL statements which demonstrate the use of SQL objec... Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
 
working with python
working with pythonworking with python
working with python
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of python
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
tools
toolstools
tools
 
data scientists and their role
data scientists and their roledata scientists and their role
data scientists and their role
 
applications
applicationsapplications
applications
 

aggregation and indexing with suitable example using MongoDB.

  • 1. Practical No:11 Problem Statement: Implement aggregation and indexing with suitable example using MongoDB. *Index* > use prac11 switched to db prac11 > db.stud.insert({_id:1,rollno:28,name:"Shail",dept:10}); > db.stud.insert({_id:2,rollno:26,name:"Shivesh",dept:10}); > db.stud.find(); { "_id" : 1, "rollno" : 28, "name" : "Shail", "dept" : 10 } { "_id" : 2, "rollno" : 26, "name" : "Shivesh", "dept" : 10 } > db.stud.insert({_id:3,rollno:22,name:"Alquama",dept:11}); > db.stud.insert({_id:4,rollno:33,name:"Swapnil",dept:11}); > > db.stud.find().pretty(); { "_id" : 1, "rollno" : 28, "name" : "Shail", "dept" : 10 } { "_id" : 2, "rollno" : 26, "name" : "Shivesh", "dept" : 10 } { "_id" : 3, "rollno" : 22, "name" : "Alquama", "dept" : 11 } { "_id" : 4, "rollno" : 33, "name" : "Swapnil", "dept" : 11 } db.stud.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.stud", "name" : "_id_" } ] db.stud.ensureIndex({name:1}); > db.stud.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.stud", "name" : "_id_" }, { "v" : 1, "key" : { "name" : 1 }, "ns" : "prac11.stud", "name" : "name_1" } db.stud.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.stud", "name" : "_id_" }, {
  • 2. "v" : 1, "key" : { "name" : 1 }, "ns" : "prac11.stud", "name" : "name_1" }, { "v" : 1, "key" : { "rollno" : 1 }, "unique" : true, "ns" : "prac11.stud", "name" : "rollno_1" } db.system.indexes.find(); { "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.stud", "name" : "_id_" } { "v" : 1, "key" : { "name" : 1 }, "ns" : "prac11.stud", "name" : "name_1" } { "v" : 1, "key" : { "rollno" : 1 }, "unique" : true, "ns" : "prac11.stud", "name" : "rollno_1" } { "v" : 1, "key" : { "_id" : 1 }, "ns" : "prac11.item", "name" : "_id_" } -------------------------------------------------------------------------------- ------------------------ *Aggergation* db.item.insert({Customer:'a',Name:"Mouse",Quantity:3,Price:200}); db.item.insert({Customer:'a',Name:"Keyboard",Quantity:5,Price:800}); > db.item.insert({Customer:'b',Name:"Mouse",Quantity:3,Price:500}); > db.item.insert({Customer:'a',Name:"Keyboard",Quantity:4,Price:2000}); > db.item.find().pretty(); { "_id" : ObjectId("5d8f128237dc2e143b51bde5"), "Customer" : "a", "Name" : "Mouse", "Quantity" : 3, "Price" : 200 } { "_id" : ObjectId("5d8f12a637dc2e143b51bde6"), "Customer" : "a", "Name" : "Keyboard", "Quantity" : 5, "Price" : 800 } { "_id" : ObjectId("5d8f12be37dc2e143b51bde7"), "Customer" : "b", "Name" : "Mouse", "Quantity" : 3, "Price" : 500 } { "_id" : ObjectId("5d8f12da37dc2e143b51bde8"), "Customer" : "a", "Name" : "Keyboard", "Quantity" : 4, "Price" : 2000 } > db.item.aggregate([{$group:{_id:"Name",total:{$sum:1}}}]); { "result" : [ { "_id" : "Name", "total" : 4 } ], "ok" : 1 }