Database Reference
In-Depth Information
reduce : function (items,prev)
{
prev.Total += 13
}
}
)
[
{
"Title" : "Nevermind",
"Total" : 1
},
{
"Title" : "Definitive Guide to MongoDB, The",
"Total" : 2
}
]
In addition to the key , initial , and reduce parameters, you can specify three more optional parameters:
keyf : You can use this parameter to replace the key parameter if you do not wish to group the
results on an existing key in your documents. Instead, you would group them using another
function you design that specifies how to do grouping.
cond : You can use this parameter to specify an additional statement that must be true before
a document will be grouped. You can use this much as you use the find() query to search for
documents in your collection. If this parameter isn't set (the default), then all documents in
the collection will be checked.
finalize : You can use this parameter to specify a function you want to execute before the
final results are returned. For instance, you might calculate an average or perform a count and
include this information in the results.
the group() function does not currently work in sharded environments. For these, you should use the
mapreduce() function instead. also, the resulting output cannot contain more than 10,000 keys in all with the group()
function, or an exception will be raised. this too, can be bypassed by using mapreduce() .
Note
Working with Conditional Operators
MongoDB supports a large set of conditional operators to better filter your results. The following sections provide an
overview of these operators, including some basic examples that show you how to use them. Before walking through
these examples, however, you should add a few more items to the database; doing so will let you see the effects of
these operators more plainly:
dvd = ( { "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999,
"Cast" : ["Keanu Reeves","Carrie-Anne Moss","Laurence Fishburne","Hugo
Weaving","Gloria Foster","Joe Pantoliano"] } )
{
"Type" : "DVD",
"Title" : "Matrix, The",
 
 
Search WWH ::




Custom Search