Assignment No 11
Assignment No 11
11
Course Outcome:
Map-reduce is a data processing paradigm for condensing large volumes of data into useful aggregated results.
MongoDB uses mapReduce command for map-reduce operations. MapReduce is generally used for processing
large data sets. In simple terms, the mapReduce command takes 2 primary inputs, the mapper function and the
reducer function .
Working of Mapper and Reducer Function :
MapReduce is a two-step approach to data processing. First you map, and then you reduce. The mapping step
transforms the inputted documents and emits a key=>value pair (the key and/or value can be complex). Then,
key/value pairs are grouped by key, such that values for the same key end up in an array. The reduce gets a key
and the array of values emitted for that key, and produces the final result. The map and reduce functions are
written in JavaScript. A Mapper will start off by reading a collection of data and building a Map with only the
required fields we wish to process and group them into one array based on the key. And then this key value pair
is fed into a Reducer, which will process the values.
MapReduce Command:
syntax of the basic mapReduce command:
db.collection.mapReduce(function() {emit(key,value);}, //map function
function(key,values) {return reduceFunction}, //reduce function
{out: collection, query: document, sort: document, limit: number})
The map-reduce function first queries the collection, then maps the result documents to emit key-value pairs
which is then reduced based on the keys that have multiple values. MapReduce Command:
syntax of the basic mapReduce command:
db.collection.mapReduce(function() {emit(key,value);}, //map function function(key,values) {return
reduceFunction}, //reduce function
{out: collection, query: document, sort: document, limit: number}) The map-reduce function first queries the
collection, then maps the result documents to emit key-value pairs which is then reduced based on the keys that
have multiple values.
DBMS Lab ThirdYear Computer Engineering
db.mapc.insert({key:”a”, value:2})
db.mapc.insert({key:”a”, value:4})
Collection “city “ which contains the documents given as below(Perform on Mongo Terminal)
DBMS Lab ThirdYear Computer Engineering
city:”pune”,
type:”urban”,
state:”MH”,
population:”5600000”