title: MongoDB MapReduce : use positional operator $ in map function
body: <p>I have a collection with entries that look like that :</p>
  
  <p>{"userid": 1, "contents": [ { "tag": "whatever", "value": 100 },  {"tag": "whatever2", "value": 110 } ] }</p>
  
  <p>I'm performing a MapReduce on this collection with queries such as {"contents.tag": "whatever"}.</p>
  
  <p>What I'd like to do in my map function is emiting the field "value" corresponding to the entry in the array "contents" that matched the query <strong>without having to iterate through the whole array</strong>. Under normal circumstances, I could do that using the $ positional operator with something like contents.$.value. But in the MapReduce case, it's not working.</p>
  
  <p>To summarize, here is the code I have right now :`</p>
  
  <pre><code>map=function(){
          emit(this.userid, WHAT DO I WRITE HERE TO EMIT THE VALUE I WANT ?);
      }
      reduce=function(key,values){
          return values[0]; //this reduce function does not make sense, just for the example
      }
      res=db.runCommand(
      {
          "mapreduce": "collection",
          "query": {'contents.tag':'whatever'},
          "map": map,
          "reduce": reduce,
          "out": "test_mr" 
      }
      );`
  </code></pre>
  
  <p>Any idea ?</p>
  
  <p>Thanks !</p>