Skip to content Skip to sidebar Skip to footer

Is There A Way To Clear Duplication Record From Results?

I have a view but did have duplicated documents from the results of view as like following, how can I get the duplicate results and get the unique? thank you in advance { 'total_ro

Solution 1:

The issue is your map function :

function(doc) {
if(doc){
    for (var i in doc.item){
            emit(doc.item[i].key,doc);
        }
    }  
}

By doing that, you emit the same document several times, therefore it shouldn't come as a surprise that you have duplicate documents in your view's results. If you want to return all the items for a document without any duplicate, you can do something as simple as that :

function(doc) {
  if(doc.item) {
    emit(doc.item, null)
  }     
} 

Also please note that I do emit(doc.item, null) and not emit(doc.item, doc). It is a bad practice to emit the document, you should instead query the view with option include_docs=true. Otherwise your view index will have the same size as your database.


Post a Comment for "Is There A Way To Clear Duplication Record From Results?"