Database Reference
In-Depth Information
"vegetables" : "pumpkin"
},
{
"fruits" : [
"pear",
"lemon",
"cherry"
],
"vegetables" : "mushroom"
},
{
"fruits" : [
"pear",
"lemon",
"cherry"
],
"vegetables" : "capsicum"
}
],
"ok" : 1
}
And that's how you can use the $skip operator to reduce the number of entries returned. You can also use the
complementary $limit operator to limit the number of results in the same manner and even combine them to pick
out a set number of results in the middle of a collection. Let's say we wanted results 1500-1510 of our 3000-entry data
set. We could provide a $skip value of 1500 and a $limit of 10, which would return only the 10 results we wanted.
We've reviewed just a few of the top-level pipeline operators available within the MongoDB aggregation
framework. There are a whole host of smaller operators that can be used within the top-level pipeline operators as
pipeline expressions . These include some geographic functions, mathematics functions such as average, first and last,
and a number of date/time and other operations. And all of these can be used and combined to perform aggregation
operations like the ones we have covered. Just remember that each operation in a pipeline will be performed on the
results of the previous operation and that you can output and step through them to create your desired result.
MapReduce
MapReduce is one of the most complex query mechanisms within MongoDB. It works by taking two JavaScript
functions, map and reduce . These two functions are completely user-defined, and this gives you an incredible
amount of flexibility in what you can do! A few short examples will demonstrate some of the things you can do
with MapReduce.
How MapReduce Works
Before we dive into the examples, it's a good idea to go over what Map/Reduce is and how it works. In MongoDB's
implementation of MapReduce we issue a specialized query to a given collection, and all matching documents from
that query are then input into our map function. This map function is designed to generate key/value pairs. Any set
of keys that have multiple values are then input to the reduce function, which returns the aggregated result of the
input data. After this there is one remaining optional step in which data can be finished for nice presentation by a
finalize function.
 
Search WWH ::




Custom Search