title: MongoDB: $mod operator in aggregation pipeline
body: <p>I have a <code>restaurants</code> collection that contains 3772 documents and I am trying to calculate the total number of documents that contain a <code>score</code> in first element of the <code>grades</code> array that's a multiple of 7 using the aggregation framework.</p>
  
  <p><strong>Query:</strong></p>
  
  <pre><code>db.restaurants.aggregate([
  {$project: {remainder: {$mod: ["$grades.0.score", 7]},
              restaurant_id: 1,
              name: 1,
              grades: 1
              }
  },
  {$match: {remainder: {$eq: 0}}},
  {$group: {_id: null, total: {$sum: 1}}}
  ])
  </code></pre>
  
  <p>However, I am getting an error message that's caused by the use of the <code>$mod</code> operator in the <code>$project</code> pipeline stage. The error message is the following:</p>
  
  <blockquote>
    <p>$mod only supports numeric types, not Array and NumberDouble</p>
  </blockquote>
  
  <p>However, both <code>$grades.0.score</code> and <code>7</code> are integers, right? What should I change to make this query work as intended?</p>
  
  <p><strong>Example document:</strong></p>
  
  <pre><code>{
  "_id" : ObjectId("57290430139a4a37132c9e93"),
  "address" : {
      "building" : "469",
      "coord" : [
          -73.961704,
          40.662942
      ],
      "street" : "Flatbush Avenue",
      "zipcode" : "11225"
  },
  "borough" : "Brooklyn",
  "cuisine" : "Hamburgers",
  "grades" : [
      {
          "date" : ISODate("2014-12-30T00:00:00Z"),
          "grade" : "A",
          "score" : 8
      },
      {
          "date" : ISODate("2014-07-01T00:00:00Z"),
          "grade" : "B",
          "score" : 23
      },
      {
          "date" : ISODate("2013-04-30T00:00:00Z"),
          "grade" : "A",
          "score" : 12
      },
  ],
  "name" : "Wendy'S",
  "restaurant_id" : "30112340"
  }
  </code></pre>