couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Priem <pr...@email.unc.edu>
Subject Find CouchDB docs missing an arbitrary field
Date Tue, 31 May 2011 21:03:44 GMT
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] 
http://wiki.apache.org/couchdb/View_Snippets#Retrieving_documents_without_a_certain_field

(apologies for crosspost at 
http://stackoverflow.com/questions/6183352/find-couchdb-docs-missing-an-arbitrary-field) 


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

Mime
View raw message