couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail A. Pokidko" <mikhail.poki...@gmail.com>
Subject Re: searching for something like AND clause
Date Thu, 02 Sep 2010 10:32:45 GMT
On Thu, Sep 2, 2010 at 2:18 PM, Wout Mertens <wout.mertens@gmail.com> wrote:
> Hi Mikhail,
>
> you should write your views so they do not change.

Yeah, finally i undestood this ehan found out that Date() inside view
have showd unpected results))


> For the expiring dates, that means you need to make the expiration date a key and then
you can query all entries that expire later than a given date.
>
> function(doc) {
>   doc.type == 'offer' && emit (doc.expires,doc);
> }

Unfortunately simple view that returns unexpired offers is not enough

>
> Since you want to filter on city AND date, you can do
>
> function(doc) {
>   doc.type == 'offer' && emit ([doc.city,doc.expires],doc);
> }
>
> and then you can get all offers for a certain city by querying with startkey ["Moscow",Date()]
>
> Functions are untested and I'm a little rusty in Javascript so they may be wrong but
you get the idea :)

I`ve tried such combinations - version with emit([doc.city,
doc.expires],doc) i find a little bit clumsy :
http://localhost:5984/dbname/_design/design/_view/1/?startkey=[%22Moscow%22,%20%222010/08/31%22]&endkey=[%22Moscow%22,%20%222010/09/22%22]
- it would be difficult to wrap with rewrites to something like
http://mysite.com/city/Moscow, i mean date-key, not city-key.

So i thought there may be more elegant way.



-- 
xmpp: pma AT altlinux DOT org

Mime
View raw message