Suppose I have web application errors reported to mongo db. To fetch them (grouped by URLs) I use the following query:
db.errors.group({
cond: {
date:{
$gt:new Date(2013,0,3, 6, 0, 0),
$lt:new Date(2013,0,3, 8, 0, 0)
}
},
key: {
url: 1
},
initial: {
csum: 0
},
reduce:
function(obj, prev) {
prev.csum++;
}
})
What should I do if I would like to count the errors by a site url (as opposed to a page url)? I mean, that http://www.mysite.com/page1 and http://www.mysite.com/page2 will be counted in the same bucket. Ideally, it would be a function in the key section of the query somehow…
To extend JohnnyHK’s answer:
Returns:
With a large dataset it’s not going to be fast though. If you control the code that generates the errors it might be easier to add a
domainfield you could group on.