couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: Couchdb views using time
Date Sat, 10 Jan 2009 21:44:16 GMT

On 10 Jan 2009, at 22:39, paul jobs wrote:

> how to use startkey=now-1 hour

you need to put in actual values there. CouchDB does not do any magic  
date tricks.
your application needs to calculate what one hour before  
"2008-12-16T14:45:41Z"
is and put that into the ?startkey= parameter.

Cheers
Jan
--

>
>
> http://server:5984/truthbox/_view/truthbox/by_created?count=10&group=true
> gives ou this
>
> {"total_rows":37718,"offset":0,"rows":[
> {"id 
> ":"47d7bef01ae278afd16f56736ae5c87b 
> ","key":"2008-12-16T14:45:41Z","value": 
> {"_id 
> ":"47d7bef01ae278afd16f56736ae5c87b","_rev":"641284558","msg":"right
> to those cute lickle tosies....and i will chew your toenails when im
> there....right up till i get to your pubic
> hair....x","fromuid":900415470,"touid": 
> 573627038,"subject":"PMSL","created":"2008-12-16T14:45:41Z"}},
> ]}
>
>
> http://server:5984/truthbox/_view/truthbox/by_created?count=10&group=true*&startkey=(now
> - 1 hour)*
> gives nothing as output
>
> "key":"2008-12-16T14:45:41Z",
>
>
> On Sat, Jan 10, 2009 at 12:44 AM, Antony Blakey <antony.blakey@gmail.com 
> >wrote:
>
>>
>> On 10/01/2009, at 7:01 PM, paul jobs wrote:
>>
>> so paul what you are saying is this
>>> so if we use sortable_timestamp or created/date/time in my case
>>> the rows are automatically sorted in descending order and use the  
>>> 1st 100
>>> u
>>> get and process them in python
>>>
>>> is it possible to construct this in the view itself and get like  
>>> the 340
>>> items that are created in the last one hour without resorting to  
>>> python
>>>
>>
>> No. You are suggesting having the view consist of those records  
>> from the
>> last hour. The problem is that CouchDB requires that the map and  
>> reduce
>> functions are strictly functional i.e. the will always produce the  
>> same
>> output for the same input. CouchDB will not work if this isn't the  
>> case
>> because the view rows created by a map will be regenerated only  
>> when the
>> document from which they are computed, changes.
>>
>> In your case you are expecting that the output will depend on the  
>> current
>> time.
>>
>> OTOH, why do you need to process them in python - the view request to
>> return those records from the last hour is easy - just use  
>> startkey=(now - 1
>> hour).
>>
>>
>>> Sorry if i am asking something basic
>>> Thanks
>>> On Fri, Jan 9, 2009 at 11:51 PM, Paul Davis <paul.joseph.davis@gmail.com
>>>> wrote:
>>>
>>>
>>> On Fri, Jan 9, 2009 at 9:41 PM, paul jobs <webjogger@gmail.com>  
>>> wrote:
>>>>
>>>>> Thanks chris
>>>>> Ok, but how to get the list of items that are in the last one  
>>>>> hour,
>>>>> since
>>>>> the list is about 3 million users
>>>>>
>>>>
>>>> Paul,
>>>>
>>>> emit([doc.user, doc.sortable_timestamp], null)
>>>>
>>>> Paul
>>>>
>>>>
>>>> so extracting the 3 million using this view and then processing the
>>>>>
>>>> results
>>>>
>>>>> in python doesnt seem feasible
>>>>> thanks a lot
>>>>>
>>>>> On Fri, Jan 9, 2009 at 10:52 PM, Chris Anderson <jchris@gmail.com>
>>>>>
>>>> wrote:
>>>>
>>>>>
>>>>> just have a map view that calls emit(doc.timestamp, null) as  
>>>>> long as
>>>>>> your timestamp format sorts correctly.
>>>>>>
>>>>>> On Fri, Jan 9, 2009 at 3:47 PM, paul jobs <webjogger@gmail.com>
 
>>>>>> wrote:
>>>>>>
>>>>>>> This is very useful for eg., to delete posts older than one day
>>>>>>> get users who logged in the last 1 hour etc
>>>>>>>
>>>>>>> On Fri, Jan 9, 2009 at 3:47 PM, paul jobs <webjogger@gmail.com>
>>>>>>>
>>>>>> wrote:
>>>>
>>>>>
>>>>>>> select * from users where ((extract('epoch' from now()) -
>>>>>>>>
>>>>>>> extract('epoch'
>>>>>>
>>>>>>> from last_login)) < 3000000) order by last_login DESC
>>>>>>>>
>>>>>>>> is it possible to construct such views using couchdb  
>>>>>>>> permanent views?
>>>>>>>>
>>>>>>>> thanks
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Chris Anderson
>>>>>> http://jchris.mfdz.com
>>>>>>
>>>>>>
>>>>>
>>>>
>> Antony Blakey
>> -------------
>> CTO, Linkuistics Pty Ltd
>> Ph: 0438 840 787
>>
>> It's amazing that the one side of the conversation that survived is  
>> "I
>> don't know art, but I know what I like". The reply from the artist  
>> was
>> "Madam, so does a cow".
>> -- Carl Kirkendall
>>
>>
>>


Mime
View raw message