3. DBï§ MongoDB is a cross-platform, document oriented database that provides, high
performance, high availability, and easy scalability. MongoDB works on concept of
collection and document.MongoDB is written in C++.
ï§ MongoDB is a database program that is :
ï§ Free â You donât have to pay a price to use it in your application.
ï§ Open Source â The source is open and open source community contributes to the
development of MongoDB database program.
ï§ Cross Platform â MongoDB build on a platform (say Linux) works on other
platforms(Windows, MacOS, etc.) as well without any modification to the code.
ï§ Document Oriented â MongoDB stores records in form of JSON like documents.
There are many advantages in doing so. A notable advantage is that adding new
features(columns in relational database) to the database requires no hassle.
ï§ NoSQL (Not only SQL) â MongoDB uses document based databases where each
document is a key with complex value. The document value can contain multiple
key-value pairs.
6. DB
ï§ MongoDB packs the advantages of NoSQL. NoSQL database concepts were
developed to make the applications more modern and fast. NoSQL databases
overcome the disadvantages of SQL.
ï§ Structured Data â MongoDB can handle structured data(like a spread-sheet
or table), semi structured data and unstructured data (data with no rules,
examples are multimedia content).
ï§ Agile Development â All the NoSQL features of MongoDB makes it perfect fit
for Agile methodology for developing applications. Modern applications are
designed to have fewer development time and quick updates to the ever
ending requirements.
ï§ Scalability â MongoDB is horizontally scalable and thus can respond to the
increasing application requirements with less cost.
ï§ Replication â You can setup replication of data between MongoDB instances.
When an instance goes down, other instance can handle the requests with
same data available.
ï§ MapReduce â You can apply MapReduce algorithm on the MongoDB
Collections to pull out some useful reports.
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce
7. DB MAP
REDUCE
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.
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce
8. REDUCE
ï§Following is the syntax of the basic mapReduce
command â
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.
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce
9. REDUCE
ï§In the above syntax â
ï§map is a javascript function that maps a value with a
key and emits a key-value pair
ï§reduce is a javascript function that reduces or groups
all the documents having the same key
ï§out specifies the location of the map-reduce query
result
ï§query specifies the optional selection criteria for
selecting documents
ï§sort specifies the optional sort criteria
ï§limit specifies the optional maximum number of
documents to be returned
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce
10. REDUCE
ï§ Consider the following document structure storing user posts. The document
stores user_name of the user and the status of post.
ï§ Now, we will use a mapReduce function on our posts collection to select all
the active posts, group them on the basis of user_name and then count the
number of posts by each user using the following code â
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce
11. ï§ The above mapReduce query outputs the following result â
ï¶ The result shows that a
total of 4 documents
matched the query
(status:"active"), the map
function emitted 4
documents with key-value
pairs and finally the reduce
function grouped mapped
documents having the same
keys into 2.
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce
12. ï§ To see the result of this mapReduce query, use the find operator â
ï§ The above query gives the following result which indicates that both users tom
and mark have two posts in active states â
ï§ In a similar manner, MapReduce queries can be used to construct large
complex aggregation queries. The use of custom Javascript functions make use
of MapReduce which is very flexible and powerful.
What is
MongoDB?
MongoDB-
MapReduce
MapReduce-
Command
Syntax of Mongo-
MapReduce
Using
MapReduce