SlideShare a Scribd company logo
1 of 2
Download to read offline
Practical No: 13
Problem Statement: Design and Implement any 5 query using MongoDB
> use prac13
switched to db prac13
> db.stud.insert({roll:1,name:"Alquama"});
WriteResult({ "nInserted" : 1 })
> db.stud.insert({roll:22,name:"Shivesh"});
WriteResult({ "nInserted" : 1 })
> db.stud.insert({roll:32,name:"Sahil"});
WriteResult({ "nInserted" : 1 })
> db.stud.insert({roll:33,name:"Swapnil"});
WriteResult({ "nInserted" : 1 })
> db.stud.insert({roll:20,name:"Swap"});
WriteResult({ "nInserted" : 1 })
> db.stud.find().pretty();
{
"_id" : ObjectId("5d988ad7ad81806e4cedd8ce"),
"roll" : 1,
"name" : "Alquama"
}
{
"_id" : ObjectId("5d988ae8ad81806e4cedd8cf"),
"roll" : 22,
"name" : "Shivesh"
}
{
"_id" : ObjectId("5d988af5ad81806e4cedd8d0"),
"roll" : 32,
"name" : "Sahil"
}
{
"_id" : ObjectId("5d988b09ad81806e4cedd8d1"),
"roll" : 33,
"name" : "Swapnil"
}
{
"_id" : ObjectId("5d988b7ead81806e4cedd8d2"),
"roll" : 20,
"name" : "Swap"
}
db.stud.find({roll:22});
{ "_id" : ObjectId("5d988ae8ad81806e4cedd8cf"), "roll" : 22, "name" :
"Shivesh" }
## sort
**descending
> db.stud.find({},{"roll":1,_id:0}).sort({"roll":-1})
{ "roll" : 33 }
{ "roll" : 32 }
{ "roll" : 22 }
{ "roll" : 20 }
{ "roll" : 1 }
**ascending
db.stud.find({},{"roll":1,_id:0}).sort({"roll":1})
{ "roll" : 1 }
{ "roll" : 20 }
{ "roll" : 22 }
{ "roll" : 32 }
{ "roll" : 33 }
##Limit
> db.stud.find({},{"roll":1,"name":1,_id:0}).limit(2)
{ "roll" : 1, "name" : "Alquama" }
{ "roll" : 22, "name" : "Shivesh" }
##skip
db.stud.find({},{"roll":1,"name":1,_id:0}).limit(1).skip(1);
{ "roll" : 22, "name" : "Shivesh" }
> db.stud.find({},{"roll":1,"name":1,_id:0}).skip(2);
{ "roll" : 32, "name" : "Sahil" }
{ "roll" : 33, "name" : "Swapnil" }
{ "roll" : 20, "name" : "Swap" }

More Related Content

More from bhavesh 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
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing 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
 
statistics techniques to deal with data
statistics techniques to deal with datastatistics techniques to deal with data
statistics techniques to deal with databhavesh lande
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data sciencebhavesh lande
 

More from bhavesh lande (15)

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.
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing 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
 
statistics techniques to deal with data
statistics techniques to deal with datastatistics techniques to deal with data
statistics techniques to deal with data
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data science
 

Design and Implement any 5 query using MongoDB

  • 1. Practical No: 13 Problem Statement: Design and Implement any 5 query using MongoDB > use prac13 switched to db prac13 > db.stud.insert({roll:1,name:"Alquama"}); WriteResult({ "nInserted" : 1 }) > db.stud.insert({roll:22,name:"Shivesh"}); WriteResult({ "nInserted" : 1 }) > db.stud.insert({roll:32,name:"Sahil"}); WriteResult({ "nInserted" : 1 }) > db.stud.insert({roll:33,name:"Swapnil"}); WriteResult({ "nInserted" : 1 }) > db.stud.insert({roll:20,name:"Swap"}); WriteResult({ "nInserted" : 1 }) > db.stud.find().pretty(); { "_id" : ObjectId("5d988ad7ad81806e4cedd8ce"), "roll" : 1, "name" : "Alquama" } { "_id" : ObjectId("5d988ae8ad81806e4cedd8cf"), "roll" : 22, "name" : "Shivesh" } { "_id" : ObjectId("5d988af5ad81806e4cedd8d0"), "roll" : 32, "name" : "Sahil" } { "_id" : ObjectId("5d988b09ad81806e4cedd8d1"), "roll" : 33, "name" : "Swapnil" } { "_id" : ObjectId("5d988b7ead81806e4cedd8d2"), "roll" : 20, "name" : "Swap" } db.stud.find({roll:22}); { "_id" : ObjectId("5d988ae8ad81806e4cedd8cf"), "roll" : 22, "name" : "Shivesh" } ## sort **descending > db.stud.find({},{"roll":1,_id:0}).sort({"roll":-1}) { "roll" : 33 } { "roll" : 32 } { "roll" : 22 } { "roll" : 20 } { "roll" : 1 } **ascending db.stud.find({},{"roll":1,_id:0}).sort({"roll":1}) { "roll" : 1 } { "roll" : 20 } { "roll" : 22 } { "roll" : 32 } { "roll" : 33 }
  • 2. ##Limit > db.stud.find({},{"roll":1,"name":1,_id:0}).limit(2) { "roll" : 1, "name" : "Alquama" } { "roll" : 22, "name" : "Shivesh" } ##skip db.stud.find({},{"roll":1,"name":1,_id:0}).limit(1).skip(1); { "roll" : 22, "name" : "Shivesh" } > db.stud.find({},{"roll":1,"name":1,_id:0}).skip(2); { "roll" : 32, "name" : "Sahil" } { "roll" : 33, "name" : "Swapnil" } { "roll" : 20, "name" : "Swap" }