title: How to use a Javascript object inside mongodb aggregation pipeline?
body: <p>I have a JS object <code>norm</code> which I want to use inside mongo aggregation pipeline, like this:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>var norm = { 
      1: 1, 
      2: 1.16,
      3: 1.413,
      4: 1.622,
      5: 1.6,
      6: 1.753,
      7: 3.001,
      8: 2.818,
      9: 3.291,
      10: 2.824,
      11: 2.993,
      12: 2.699,
      13: 1.099,
      14: 1.035,
      15: 1.172,
      16: 1.013,
      17: 0.9936,
      18: 1.069
  };
  
  db.mycoll.aggregate([
      {$match : 
          {"_id.day" : ISODate("2014-06-19T00:00:00.000Z"), 
           "_id.lt" : "l",
           "_id.rt" : "rltdlsts",
           "_id.m": false   }
      },
  
      {$unwind: '$value.rl'},
  
      {$match: {'value.rl.p': {$gte: 1, $lte: 18} } },
  
      {$group: {_id: '$value.rl.a', 
                  v: {$sum: '$value.rl.v'},
                  nv: { $sum: { $multiply: [ norm['$value.rl.p'], '$value.rl.v' ] } },
                  c: {$sum: '$value.rl.c'}
              }},
  
      {$project: {
          _id: "$_id",
          'v': "$v",
          'c': "$c",
          'nv': "$nv"
        }
      },
  
      {$sort: {'_id': 1}}
  ])
  </code></pre>
  
  <p>I get results like this, where <code>nv</code> is always 0:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
      "result" : [ 
          {
              "_id" : 1,
              "v" : 89172,
              "nv" : 0,
              "c" : 604
          }, 
          {
              "_id" : 4,
              "v" : 67872,
              "nv" : 0,
              "c" : 296
          }, 
          {
              "_id" : 5,
              "v" : 33999,
              "nv" : 0,
              "c" : 13
          }, 
          {
              "_id" : 6,
              "v" : 4727,
              "nv" : 0,
              "c" : 6
          }, 
          {
              "_id" : 8,
              "v" : 913118,
              "nv" : 0,
              "c" : 14055
          }, 
          {
              "_id" : 9,
              "v" : 204099,
              "nv" : 0,
              "c" : 3021
          }, 
          {
              "_id" : 11,
              "v" : 151711,
              "nv" : 0,
              "c" : 1075
          }, 
          {
              "_id" : 12,
              "v" : 196369,
              "nv" : 0,
              "c" : 601
          }, 
          {
              "_id" : 13,
              "v" : 277705,
              "nv" : 0,
              "c" : 2302
          }, 
          {
              "_id" : 14,
              "v" : 64005,
              "nv" : 0,
              "c" : 970
          }, 
          {
              "_id" : 15,
              "v" : 54558,
              "nv" : 0,
              "c" : 326
          }, 
          {
              "_id" : 16,
              "v" : 74576,
              "nv" : 0,
              "c" : 305
          }, 
          {
              "_id" : 17,
              "v" : 1144,
              "nv" : 0,
              "c" : 1
          }, 
          {
              "_id" : 18,
              "v" : 1023,
              "nv" : 0,
              "c" : 0
          }, 
          {
              "_id" : 19,
              "v" : 54511,
              "nv" : 0,
              "c" : 98
          }, 
          {
              "_id" : 20,
              "v" : 674,
              "nv" : 0,
              "c" : 0
          }, 
          {
              "_id" : 21,
              "v" : 3359,
              "nv" : 0,
              "c" : 4
          }, 
          {
              "_id" : 22,
              "v" : 496402,
              "nv" : 0,
              "c" : 3786
          }, 
          {
              "_id" : 23,
              "v" : 293212,
              "nv" : 0,
              "c" : 1904
          }, 
          {
              "_id" : 24,
              "v" : 764087,
              "nv" : 0,
              "c" : 8847
          }, 
          {
              "_id" : 25,
              "v" : 291358,
              "nv" : 0,
              "c" : 7012
          }, 
          {
              "_id" : 28,
              "v" : 2933,
              "nv" : 0,
              "c" : 27
          }
      ],
      "ok" : 1
  }
  </code></pre>
  
  <p>How to fix this?</p>