MongoDB Aggregation Framework with Mapper-Reducer Program(34)

Lakshmi Priya Patro
3 min readJan 24, 2022

What are Databases?

A database is an organized collection of structured information, or data, typically stored electronically in a computer system.

A database is usually controlled by a database management system(DBMS). Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system.

What is MongoDB?

MongoDB is an open-source document-oriented database that is designed to store a large scale of data and also allows you to work with that data very efficiently. It is categorized under the NoSQL (Not only SQL) database because the storage and retrieval of data in MongoDB are not in the form of tables.

What is MongoDB Aggregation Framework?

Aggregation operations process data records and return computed results. Aggregation operations group values from multiple documents together and can perform a variety of operations on the grouped data to return a single result.

MongoDB provides three ways to perform aggregation: the aggregation pipeline, the map-reduce function, and single-purpose aggregation methods.

What is Map Reduce Function?

Map-reduce is a data processing paradigm for condensing large volumes of data into useful aggregated results.

Today we are gonna perform MongoDB map-reduce program and aggregation framework example

STEP-1: Import the data into the MongoDB database

Here,

person.json → Data File

d →Use for Creating database in MongoDB

c →Use for Creating collections in MongoDB

- -jsonArray →Format of data.

STEP-2: Show Database in MongoDB

STEP-3: Show Collections in MongoDB

STEP-4: Aggregate function in MongoDB

Aggregation

Here,

mapper→Collection Name

aggregate()→MongoDB pre-created function

$match→ it use the pre-define keyword to match the patter

.pretty()→ to see the output in pretty format

STEP-5: Creating Mapper Function

STEP-6: Creating Reducer Function

STEP-7: Mapper-Reducer Program in MongoDB

STEP-8: Show collections Created by Mapper-Reducer Program

STEP-9: As you can see myoutput1 database created by Mapper-Reducer Program

Here _id is equivalent to “location.state” field of the original dataset.

Thanks for Reading!!

--

--