title: Mongodb : Mapreduce query filter positional operator
body: <p>I have a huge data set (in millions) in the following format :</p>
  
  <pre><code>{
    "userid" : "codejammer",
    "data" : [       
     {"type" : "number", "value" : "23748"},
     {"type" : "message","value" : "one"}
    ]
  }
  </code></pre>
  
  <p>I want to get count of <code>message</code> with value <code>one</code> for <code>userid</code> - <code>codejammer</code> </p>
  
  <p>The following is the mapreduce function I am using :
  Map :</p>
  
  <pre><code>var map = function(){
     emit(this.data[0].value,1);
  }
  </code></pre>
  
  <p>Reduce</p>
  
  <pre><code>var reduce = function(key,values){
      return Array.sum(values);
  }
  </code></pre>
  
  <p>Options</p>
  
  <pre><code>var options = {
               "query":{"userid" : "codejammer",
                   "data.type" : "message"},
               "out" : "aggregrated"
              }
  </code></pre>
  
  <p>The mapreduce function executes successfully with the following output:</p>
  
  <pre><code>{
   "_id" : 23748,
    "value" : 1
  }
  </code></pre>
  
  <p>But, I am expecting the following output :</p>
  
  <pre><code>{
   "_id" : one,
   "value" : 1
  }
  </code></pre>
  
  <p>The <code>query</code> filter in options, is sending the entire array to map function even though I specifically ask for <code>data.type : "message"</code></p>
  
  <p>Is there any way to use <a href="http://docs.mongodb.org/manual/reference/method/db.collection.find/#projections" rel="nofollow">projection</a> operator in <code>query</code> filter to get only the required item in array ?</p>
  
  <p>Thank you very much for your help.</p>