简体   繁体   中英

CouchDB how to exclude documents from View

I have a CouchDB View to return all documents meeting a certain criteria. I have also run "all_docs" against this same DB. In this particular case, my View returns 845 docs while all_docs returns 1127 docs.

Is there a way to code a View to effectively do the inverse, and return all documents NOT meeting my specified criteria? since my DB contains 1127 total docs and my View contains 845 docs, how do I identify the 282 difference?

You can either have two views or one single view.

Single view(persons)

function(doc){
  var matchMyCriteria = doc.type ==="person";
  emit(matchMyCriteria);
}

If I want every document document that are of type "person", I query:

_design/docname/_view/by_person?key="true"

If I want the every other documents

_design/docname/_view/by_person?key="false"


Two view(persons)

persons

function(doc){
  if(doc.type == "person")
     emit(doc.id);
}

not_person

function(doc){
  if(doc.type != "person")
     emit(doc._id);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM