couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabor Ratky <>
Subject Re: Find CouchDB docs missing an arbitrary field
Date Wed, 01 Jun 2011 08:00:44 GMT
You can't do this in a traditional CouchDB view unless you have a set list of fields you're
checking for. Unless you want to emit all possible field names that don't exist ;)

I would probably use couchdb-lucene [1], and index all participating documents with a given
term (e.g. a type field in the documents) along with the names of the field THAT EXIST. You
will then be able to search for "type:foo -field:baz" [2] in lucene query syntax and get back
all documents that are type:foo but do not contain 'baz'.


[2] In the example, the type of the document was added under the field 'type' into the lucene
index, where the names of the field as 'field' field. See the indexing options in [1].
On Tuesday, May 31, 2011 at 11:03 PM, Jason Priem wrote:
> Hi all,
> I need a CouchDB view where I can get back all the documents that don't 
> have an arbitrary field. This is easy to do if you know in advance what 
> fields a document *might* not have. For example[1], this lets you send 
> view/my_view/?key="foo" to easily retrieve docs without the "foo" field:
> function (doc) {
>  var fields = [ "foo", "bar", "etc" ];
>  for (var idx in fields) {
>  if (!doc.hasOwnProperty(fields[idx])) {
>  emit(fields[idx], 1);
>  }
>  }
> }
> However, you're limited to asking about the three fields set in the 
> view; something like view/my_view/?key="baz" won't get you anything, 
> even if you have many docs missing field baz. I need a view where it 
> will--where I don't need to specify possible missing fields in advance. 
> Any thoughts?
> [1] 
> (apologies for crosspost at 

> -- 
> Jason Priem
> UNC Royster Fellow
> School of Information and Library Science
> University of North Carolina at Chapel Hill

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message