Professional Documents
Culture Documents
Cat-1 Mongodb
Cat-1 Mongodb
Cat-1 Mongodb
(i) Display the details of the students who are getting exactly 2 merit scholarships. (2 M)
(ii) Display the details of the students who receive 10000 Rs under VIT_Endowment
scholarship year wise. (2 M)
(iii) Display the names of the students in alphabetical order from MTech_BA programme.
(2 M)
(iv) Provide the facility to update the scholarship name and amount for the particular
register number. (2 M)
(vI) Assume that there is one MCA student details in the above collection. Move the
details of that MCA student from the scholarship collection to the new collection named
as MCA collection. (3.5M)
CODE:-
db.ss.insertMany([{stuname:"sai",regno:"19MIA1071",prog:"MTECH_BA",schd
etails:[{scname:"VIT_Endowment",type:"semester",amount:10000},{scname:"
Meritscholarship",type:"yearly",amount:15000}]},
{stumane:"sree",regno:"19MIA1057",prog:"MTECH_BA",schdetails:[{scname:"
Meritscholarship",type:"yearly",amount:14000}]},
{stuname:"phani",regno:"19Mia1065",prog:"MCA",schdetails:[{scname:"VIT_E
ndowment",type:"yearly",amount:20000},{scanme:"Meritscholarship",type:"se
mster",amount:8000}]},
{stuname:"abhi",regno:"19MIA1081",prog:"MTECH_BA",schdetails:[{scname:"
Meritschoalrship",type:"yearly",amount:8000}]},
{stuname:"jay",regno:"19MIA1032",prog:"MTECH_SE",schdetails:[{scname:"M
eritscholarship",type:"semster",amount:8000}]}])
db.ss.find({schdetails:{$size:2}})
db.ss.find({prog:"MTECH_BA"}).sort({stuname:1})
db.ss.updateOne({regno:"19MIS1032"},{$set:{"schdetails.amount":10000,"sch
det.sch_name":"VIT_Endowment"}})
MCA=db.scholarships.find({"prog":"MCA"})
db.mca.insertOne(MCA)
OUTPUT:-
2. World Cricket Board maintains the details of all cricket players(name of the player,
country name, number of matches played, total runs scored, number of 100s scored) in a
mongodb cricket collection for the entire world.
(i) Perform sort operations on the total number of runs scored and link this sort
operation with indexing. Write the appropriate index creation and sort commands in
mongodb and link the relation between these two commands. (2 M)
(ii) Include the compound key field (country name, number of 100s scored) as an
indexing field to this collection and perform the suitable sort operation. Write the
possible efficient sort operations based on the indexing and give your justification. (3 M)
(iii) Analyse the performance of the sort operation done in (ii) using appropriate
MongoDB command. (2 M)
(iv) Illustrate the use of hint() command in (ii) with one example. (2 M)
(v)Display the name of the player who has scored second highest run in the world. (3 M)
(vi) As an expert suggest which field in this cricket collection will be the best indexing
attribute and give your justification. (2 M)
CODE:-
db.cric.insertMany([{plname:"rohit",countryname:"India",numofmatches:1000
,totalruns:24000,numberofhundreds:71},
{plname:"sky",countryname:"India",numofmatches:1500,totalruns:40000,num
berofhundreds:90},
{plname:"finch",countryname:"Australia",numofmatches:1800,totalruns:30000
,numberofhundreds:60},
{plname:"stoinis",countryname:"England",numofmatches:180,totalruns:1000,
numberofhundreds:10},
{plname:"smith",countryname:"Australia",numofmatches:1200,totalruns:3500
0,numberofhundreds:75}])
db.cric.createIndex({totalruns:1})
db.cric.find().sort({totalruns:1})
db.cric.createIndex({plname:1,numberofhundreds:1})
db.cric.find().sort({plname:1,numberofhundreds:1})
db.cric.find().sort({plname:1,numberofhundreds:1}).explain()
db.cric.find().hint({plname:1,numberofhundreds:1})
secondhighestrun=db.criket.find().sort({totalruns:-1}).toArray()
OUTPUT:-