couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcin Stefaniuk (JIRA)" <>
Subject [jira] [Created] (COUCHDB-1506) View returns null value after adding a document
Date Wed, 27 Jun 2012 21:52:43 GMT
Marcin Stefaniuk created COUCHDB-1506:

             Summary: View returns null value after adding a document
                 Key: COUCHDB-1506
             Project: CouchDB
          Issue Type: Bug
          Components: JavaScript View Server
    Affects Versions: 1.2
         Environment: Windows XP SP3
            Reporter: Marcin Stefaniuk

I have three types of documents: customer, refill and purchase. I defined a view that aggregates
customer data with current balance (from refill / purchase values). Values customer._id and
purchase/refill.customer are joining keys. Map function looks as follows:
function(doc) {
  if (doc.type=='purchase' || doc.type=='refill') {
    emit(doc.customer, {value: doc.value, type: doc.type});
  } else if (doc.type=='customer') {
    emit(doc._id, doc);

Reduce function is:
function(keys, values, rereduce) {
  var customer = null, sum = 0;
  values.forEach(function(element) {
    if (element.type=='purchase') {
      sum -= element.value;
    } else if (element.type=='refill') {
      sum += element.value;
    } else if (customer==null && element.type=='customer') {
      customer = element;
  }); = sum;
  return customer;

This view is working with success but after several adding of purchase documents it returns
null as value.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message