couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Stockton <chrisstockto...@gmail.com>
Subject Re: Count since
Date Wed, 25 May 2011 19:31:35 GMT
Hello,

On Wed, May 25, 2011 at 10:17 AM, Simon Woodhead
<simon.woodhead@simwood.com> wrote:
> Hi folks,
>
> I was wondering if someone could help me with a view.
>
> We're storing some Apache logs in CouchDB and I want to report on
> requests by IP address in the last n of time. The ultimate goal is to
> key on IP address, returning a count of requests within the last day.
>
> I've got the count by IP working fine with the following map/reduce:
>
> function(doc)
> {
>   emit(doc.request.REMOTE_ADDR,1);
> }
> function(keys, values, rereduce)
> {
>   return sum(values);
> }
>
> Can anyone guide me as to how to emit only records where the date/time
> (stored as REQUEST_TIME in seconds since epoch), e.g. 1306343401.
> Effectively I want the map to emit records where that field is greater
> than the current timestamp - n seconds.
>
> Any pointers greatly appreciated.
>

Something like:
function(doc)
{
  if(doc.request.REQUEST_TIME > (new Date().getTime() - N)) {
    emit(doc.request.REMOTE_ADDR,1);
  }
}

Mime
View raw message