couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: view syntax for retrieving object without a field
Date Fri, 22 Jan 2010 18:41:03 GMT
On Fri, Jan 22, 2010 at 7:38 AM, Matt Villiers <mattvilliers@yahoo.fr> wrote:
> I'm prototyping couchdb for a large application (for a possible migration from an oracle
system).
>
> I'l like to query my objects to get those _without_ a certain key.
> My data:
> {'id':'2','Type':'Article', country:'USA'}
> {'id':'3','Type':'Article', country:'USA'}
> {'id':'4','Type':'Article',}
> {'id':'5','Type':'Article', country:null}
>
> I'd like to get the object number 4 (no field 'country').
>
> I tried with this view:
>
>            function(doc) {
>                if  (doc.Type == "Article") {
>                  emit('country' in doc, doc);
>                }
>            }
>
 function(doc) {
    if (doc.Type == "Article") {
      if (doc.country) {
        emit(doc.country, null);
      } else {
        emit("--no-country", null);
      }
    }
  };

instead of "--no-country" you could emit false, but currently if there
is no .country field then CouchDB will just skip the row.

there are plans to make it so that attempts to emit undefined will be
coerced to null (this is in keeping with the ecma5 standard) but that
won't change things materially for you.

Chris





> With False as the request key but with no luck ...
>
> Is that feasible with couchdb ? Could you advise ?
>
> Best,
>
> Matt
>
>
>
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Mime
View raw message