title: Couch base map reduce query
body: <p>I have a 3 Json Documents</p>
  
  <p>Document 1</p>
  
  <pre><code>"No" : 1
  "City" : "Patiala"
  "Value" : 10
  </code></pre>
  
  <p>Document 2</p>
  
  <pre><code>"No" : 1
  "City" : "Delhi"
  "Value" : 11
  </code></pre>
  
  <p>Document 3</p>
  
  <pre><code>"No" : 1
  "City" : "Patiala"
  "Value" : 11
  </code></pre>
  
  <p>I want output like </p>
  
  <pre><code> 1    &lt;Delhi or Patiala any one city&gt;    32
  </code></pre>
  
  <p>I tried query with group level 2</p>
  
  <pre><code>map
  function(doc, meta)
  {
      emit(doc.No,[doc.Value,doc.City]);
  }
  </code></pre>
  
  <p>reduce</p>
  
  <pre><code>function(key,values,rereduce){
      if(!rereduce){
          var sum=0;
          var s=[];
          var v=[];
          v=values[1];
          s=values[0];
          for(i=0;i&lt;s.length;++i){
              sum+= s[i];
          }
          return (sum,v[0]);
      }else{
          var sum=0;
          var s=[];
          var v;
          v=values[1];
          s=values[0];
          for(i=0;i&lt;s.length;++i){
              sum+= s[i];
          }
          return (sum,v);
      }   
  }
  </code></pre>
  
  <p>and got the following error</p>
  
  <pre><code>(Reducer: Error building index for view `my_first_view`, reason: TypeError: Cannot read property 'length' of null)
  </code></pre>
  
  <p>I only want to do group by on 'No' field but display any city.</p>