couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Woodhead <>
Subject Re: Count since
Date Sun, 29 May 2011 18:23:10 GMT
Hi guys,

Thank you both for your input.

>> Something like:
>> function(doc)
>> {
>>  if(doc.request.REQUEST_TIME > (new Date().getTime() - N)) {
>>    emit(doc.request.REMOTE_ADDR,1);
>>  }
>> }
> AFAIK the view is not run dynamically but is stored in the view
> b-tree, so I'm not sure how this would work unless it was in a list
> instead. But I'd be interested to find out what the result is.

As Dave suggested this didn't work unfortunately. FWIW using '<' did
work as I guess the view did not need to be built dynamically for
that. Didn't solve my issue though as I need results since a

> Try simply sorting the view by request time (emit
> doc.request.REQUEST_TIME, doc.request.REMOTE_ADDR) and then query with
> start/end and perhaps descending=true.

This got me along the right lines but I was struggling to summarise
into ultimate counts.

I've done it in the end by emitting an array, i.e:


with _sum for the reduce.

I can then get what I need by playing about with startkey and reduce
level, e.g.:


Means I need to calculate the input timestamp dynamically but the
result is exactly what I'm after - a key of the IP address and a value
of the count of requests.

group_level=1 gives me the count by ip, group_level=2 gives me the
matching [ip, timestamp] and values of 1.

***** Email confidentiality notice *****

This message is private and confidential. If you have received this message in error, please
notify us and remove it from your system.

Simwood eSMS Limited is a limited company registered in England and Wales. Registered number:
03379831. Registered office: c/o HW Chartered Accountants, Keepers Lane, The Wergs, Wolverhampton,
WV6 8UA. Trading address: Falcon Drive, Cardiff Bay, Cardiff, CF10 4RU.

View raw message