title: Include a Javascript variable in the MongoDB aggregate query with $project
body: <p>I have a javascript loop that does a particular task of looping over a javascript hash and calling aggregate over my collection.</p>
  
  <p>I was able to insert a variable into the aggregate query for the $match function, but I cannot for the $project function.</p>
  
  <p>I want to match across the hash keys and then display the hash values in conjunction with the values already in the document that I just matched.  These hash values and label were not in the document beforehand.</p>
  
  <pre><code>var cmtss = {};
  
  for (var item in cursor['result'])
  {
      var prov = cursor['result'][item]['prov_group'];
      cmtss[cursor['result'][item]['name']] = prov;
  }
  
  for (var item in cmtss)
  {
      var cmts = "$" + cmtss[item];
  
      result = db.modems.aggregate( { $match : { cmts: item } } ,
                                    { $project : {
                                         ip : "$ip",
                                         model : "$model",
                                         cmts : "$cmts",
                                         prov_group : cmts } } );
      printjson(result);
  }
  </code></pre>
  
  <p>As you can see, I include a $match, where I want the cmts field to match to the key provided.  But with those matches I want to display the 3 fields including a brand new field that I add in but its value is the hash value from cmtss.  I tried with and without the $ operator before the value.  It is simply not displaying a prov_group at all in the result documents.</p>
  
  <p>Do I need to use $add somehow?</p>