Sometimes, we don't need the entire collection for our MapReduce process. Because of this, the mapReduce
command provides us with optional parameters to filter the input collection.
The query
parameter allows us to apply criteria using the query operators to filter the documents input into the map function. In the following code, we will filter the documents in the collection and only include the documents where the number attribute is greater than 10 ("$gt":10
):
collection.map_reduce(map_function,
reduce_function,
"output_collection",
query={"number":{"$gt":10}})
The Query Operators used in the MapReduce query parameter are the same query selectors seen in Chapter 12, Data Processing and Aggregation with MongoDB, which perform simple queries. In the following table, we present the most common operators and their...