20mia1061 (Yash Nair) - Nosql Lab-6

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

20MIA1061(YASH NAIR)_NOSQL LAB-6

Design the appropriate student collection and apply 4 types of indexing


(single key field indexing, single key field indexing with embedded data
type, multikey indexing, and compound key indexing). Perform the find and
sort operations. Also, analyze the performance of queries with and without
indexing.

Single Key Field Indexing:


Single Key field indexing with embedding data type
Multi Key indexing
Compound Key indexing
Develop a Map Reduce method in Mongo dB to display the 2nd highest
salary in each department. Design the collection accordingly and store the
output in the new collection.

var map = function(){emit(this.dept,this.marks)}

var reduce = function(key, value) {var sortMarks = value.sort(function(a, b) {


return b - a; });return { maxmax_mark2: sortMarks[1] }; };

db.student_MIA1061.mapReduce(map,reduce,{out:"Result"})

db.student_MIA1061.find()
Q3. Design a Python program to display the details of students from the
MongoDB students collection.

import pymongo
from pymongo import MongoClient
myclient = MongoClient("mongodb://127.0.0.1:27017")
mydb = myclient["db"]
mycol = mydb["student_MIA1061"]
x = mycol.find()
for i in x:
print(i)

You might also like