0% found this document useful (0 votes)
19 views3 pages

Group (B) 3

Uploaded by

surajs300303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Group (B) 3

Uploaded by

surajs300303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Group B : Lab Assignment no.

12
Title :Implement Map reduces operation with suitable example using MongoDB

dipti@dipti-VPCEG28FN:~$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Server has startup warnings:
2020-10-15T14:26:28.786+0530 I STORAGE [initandlisten]
2020-10-15T14:26:28.786+0530 I STORAGE [initandlisten] ** WARNING:
Using the XFS filesystem is strongly recommended with the WiredTiger storage
engine
2020-10-15T14:26:28.786+0530 I STORAGE [initandlisten] ** See
http://dochub.mongodb.org/core/prodnotes-filesystem
2020-10-15T14:26:36.417+0530 I CONTROL [initandlisten]
2020-10-15T14:26:36.417+0530 I CONTROL [initandlisten] ** WARNING:
Access control is not enabled for the database.
2020-10-15T14:26:36.417+0530 I CONTROL [initandlisten] ** Read and
write access to data and configuration is unrestricted.
2020-10-15T14:26:36.417+0530 I CONTROL [initandlisten]
>
> use Abhi
switched to db
Abhi

> db.createCollection('Journal');
{ "ok" : 1 }

>db.Journal.insert({'book_id':1,'book_name':'JavacdOOP','amt':500,'status':'A
vailable'});
WriteResult({ "nInserted" : 1 })

> db.Journal.insert({'book_id':1,'book_name':'JavaOOP','amt':400,'status':'Not
Available'});
WriteResult({ "nInserted" : 1 })
>db.Journal.insert({'book_id':1,'book_name':'Java','amt':300,'s
tatus':'Not Available'});
WriteResult({ "nInserted" : 1 })

>db.Journal.insert({'book_id':2,'book_name':'Java','amt':300,'s
tatus':'Available'});
WriteResult({ "nInserted" : 1 })>

>db.Journal.insert({'book_id':2,'book_name':'OPP','amt':200,'st
atus':'Available'});
WriteResult({ "nInserted" : 1 })

>db.Journal.insert({'book_id':2,'book_name':'C+','amt':200,'status':'Available'}
);
WriteResult({ "nInserted" : 1 })

>db.Journal.insert({'book_id':3,'book_name':'C+','amt':150,'status':'Available'}
);
WriteResult({ "nInserted" : 1 })

> db.Journal.insert({'book_id':3,'book_name':'C+
+','amt':200,'status':'Not Available'});
WriteResult({ "nInserted" : 1 })

> db.Journal.insert({'book_id':4,'book_name':'OPP C+
+','amt':300,'status':'Not Available'});
WriteResult({ "nInserted" : 1 })

> db.Journal.insert({'book_id':5,'book_name':'OPP C+
+','amt':400,'status':'Available'});
WriteResult({ "nInserted" : 1 })

> db.Journal.insert({'book_id':5,'book_name':'C+
+','amt':400,'status':'Available'});
WriteResult({ "nInserted" : 1 })

> db.Journal.insert({'book_id':5,'book_name':'C++
Java','amt':400,'status':'Not Available'});
WriteResult({ "nInserted" : 1 })

> var mapfunction=function(){ emit(this.book_id,this.amt)};


> var reducefunction=function(key,value){return Array.sum(value);};
> db.Journal.mapReduce(mapfunction,reducefunction,
{'out':'new'});
{
"result" : "new",
"timeMillis" : 49,"counts" : {
"input" : 12,
"emit" : 12,
"reduce" : 4,
"output" : 5
},
"ok" : 1
}

> db.Journal.mapReduce(mapfunction,reducefunction,
{'out':'new'}).find().pretty();
{ "_id" : 1, "value" : 1200 }
{ "_id" : 2, "value" : 700 }
{ "_id" : 3, "value" : 350 }
{ "_id" : 4, "value" : 300 }
{ "_id" : 5, "value" : 1200 }
>
>
> db.new.find().pretty();
{ "_id" : 1, "value" : 1200 }
{ "_id" : 2, "value" : 700 }
{ "_id" : 3, "value" : 350 }
{ "_id" : 4, "value" : 300 }
{ "_id" : 5, "value" : 1200 }
>

You might also like