You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Norman Barker <no...@gmail.com> on 2009/10/31 23:21:16 UTC

view key boolean operator

Hi,

is there a way to specify a key for a view such that the view returns
all results that don't have that key?

e.g. myview?key="~a", returns all documents with keys equal to b, c, d, ...

I appreciate that I could get all document ids and then query for all
documents with key 'a' and then return the difference but then I lose
the advantage of being able to page the result.

Has anyone tried this?

thanks,

Norman

Re: view key boolean operator

Posted by Brian Candler <B....@pobox.com>.
On Sat, Oct 31, 2009 at 04:21:16PM -0600, Norman Barker wrote:
> Hi,
> 
> is there a way to specify a key for a view such that the view returns
> all results that don't have that key?
> 
> e.g. myview?key="~a", returns all documents with keys equal to b, c, d, ...

If every document emits at least one key, then you could query twice: once
for key < a, and once for key > a.

You should be able to do this using some combination of startkey, endkey,
desc and/or inclusive_end.

Re: view key boolean operator

Posted by Paul Davis <pa...@gmail.com>.
Norman,

Your best bet would be to emit something that flags that the property
doesn't exist. Perhaps something like:

emit(doc.a || null, null)

And then query for key=null

Granted that munges when doc.a is null. To be complete you'd need to
do something like:

if(doc.a !== undefined) {
    emit([doc.a], null):
} else {
    emit(null, null);
}

HTH,
Paul Davis

On Sat, Oct 31, 2009 at 6:21 PM, Norman Barker <no...@gmail.com> wrote:
> Hi,
>
> is there a way to specify a key for a view such that the view returns
> all results that don't have that key?
>
> e.g. myview?key="~a", returns all documents with keys equal to b, c, d, ...
>
> I appreciate that I could get all document ids and then query for all
> documents with key 'a' and then return the difference but then I lose
> the advantage of being able to page the result.
>
> Has anyone tried this?
>
> thanks,
>
> Norman
>