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

PDF
DBMS 3.pdf
NithishReddy90
 
PPTX
Mongo Nosql CRUD Operations
anujaggarwal49
 
PPTX
JSON and the Oracle Database
Maria Colgan
 
PPT
Introduction to Computer Networks
Pankaj Gautam
 
PDF
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Jonathan Katz
 
PDF
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
PPTX
Indexing with MongoDB
MongoDB
 
PDF
Python Dictionary
Soba Arjun
 
DBMS 3.pdf
NithishReddy90
 
Mongo Nosql CRUD Operations
anujaggarwal49
 
JSON and the Oracle Database
Maria Colgan
 
Introduction to Computer Networks
Pankaj Gautam
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Jonathan Katz
 
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
Indexing with MongoDB
MongoDB
 
Python Dictionary
Soba Arjun
 

What's hot (20)

PPTX
Procedures and triggers in SQL
Vikash Sharma
 
PDF
Web Technology Lab files with practical
Nitesh Dubey
 
PPTX
Integrity Constraints
madhav bansal
 
PPTX
C# String
Raghuveer Guthikonda
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
PDF
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
PPTX
database language ppt.pptx
Anusha sivakumar
 
PPT
Operator Overloading
Nilesh Dalvi
 
DOCX
C++ file
Mukund Trivedi
 
DOC
Dbms lab Manual
Vivek Kumar Sinha
 
PPTX
C Language (All Concept)
sachindane
 
PPTX
Data Structures (CS8391)
Elavarasi K
 
PPTX
Key-Value Pairs
littledata
 
PDF
Introduction to Python
Mohammed Sikander
 
PPTX
React event
Ducat
 
PPTX
Presentation slides of Sequence Query Language (SQL)
Punjab University
 
DOCX
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
PPTX
HBase Vs Cassandra Vs MongoDB - Choosing the right NoSQL database
Edureka!
 
PDF
Introduction to Cassandra Architecture
nickmbailey
 
PPTX
MS Sql Server: Joining Databases
DataminingTools Inc
 
Procedures and triggers in SQL
Vikash Sharma
 
Web Technology Lab files with practical
Nitesh Dubey
 
Integrity Constraints
madhav bansal
 
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
database language ppt.pptx
Anusha sivakumar
 
Operator Overloading
Nilesh Dalvi
 
C++ file
Mukund Trivedi
 
Dbms lab Manual
Vivek Kumar Sinha
 
C Language (All Concept)
sachindane
 
Data Structures (CS8391)
Elavarasi K
 
Key-Value Pairs
littledata
 
Introduction to Python
Mohammed Sikander
 
React event
Ducat
 
Presentation slides of Sequence Query Language (SQL)
Punjab University
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
HBase Vs Cassandra Vs MongoDB - Choosing the right NoSQL database
Edureka!
 
Introduction to Cassandra Architecture
nickmbailey
 
MS Sql Server: Joining Databases
DataminingTools Inc
 
Ad

More from bhavesh lande (20)

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

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 }