title: How do I not save data in my reduce() function in MongoDB?
body: <p>In MongoDB, I am trying to write Map-Reduce functions that only saves data if it meets certain criteria.</p>
  
  <p>I cannot figure out how to <em>not</em> emit() from my reducer. It always saves the data, one way or another.</p>
  
  <p>Here is a generic example. Ignore the context of the data -- I created this data and code solely for the purpose of this question.</p>
  
  <p>Data Set:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>{ "_id" : ObjectId("52583b3a58da9769dda48853"), "date" : "01-01-2013", "count" : 1 }
  { "_id" : ObjectId("52583b3d58da9769dda48854"), "date" : "01-01-2013", "count" : 1 }
  { "_id" : ObjectId("52583b4258da9769dda48855"), "date" : "01-02-2013", "count" : 1 }
  { "_id" : ObjectId("52583b4f58da9769dda48856"), "date" : "01-03-2013", "count" : 4 }
  </code></pre>
  
  <p>Map Function:</p>
  
  <pre class="lang-js prettyprint-override"><code>// Map all data by (date, count)
  var map = function() {
      var key = this.date;
      var value = this.count;
      emit(key, value);
  }
  </code></pre>
  
  <p>Reducer that simply ignores unwanted data.</p>
  
  <pre class="lang-js prettyprint-override"><code>// Only save dates which have count &gt; 2
  var reducer = function(date, counts) {
      var sum = Array.sum(counts);
      if (sum &gt; 2) {
          return sum;
      }
  }
  </code></pre>
  
  <p>Results (Value of 1 was not ignored):</p>
  
  <pre class="lang-js prettyprint-override"><code>{ "_id" : "01-01-2013", "value" : null }
  { "_id" : "01-02-2013", "value" : 1 }
  { "_id" : "01-03-2013", "value" : 4 }
  </code></pre>
  
  <p>I also added in an empty return statement, but got the same results:</p>
  
  <pre class="lang-js prettyprint-override"><code>// Only save dates which have count &gt; 2
  var reducer = function(date, counts) {
      var sum = Array.sum(counts);
      if (sum &gt; 2) {
          return sum;
      }
      else return;
  }
  </code></pre>
  
  <p>What I would like to have happen is only the following data would exist in my output collection after running Map-Reduce. <strong>How can I accomplish this?</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>{ "_id" : "01-03-2013", "value" : 4 }
  </code></pre>