title: Mongoose - get number of matching fields
body: <p>I'm writing a REST API in Node.js using Mongoose to access the MongoDB backend database. I want to provide an API endpoint that returns a count of the number of array objects that match a particular variationStatus.</p>
  
  <p>This is what I have so far but it gives me an empty response...</p>
  
  <pre><code>//Get 'Approved' count
  app.get("/v1/approvedcount", async (request, response) =&gt; {
      var status = 'Approved';
      try {
          var result = await variationsModel.find({ 'variations.variationStatus': status }).exec().count();
          response.send(result);
      } catch (error) {
          response.status(500).send(error);
      }
  } )
  </code></pre>
  
  <p>And this is my model...</p>
  
  <pre><code>const variationsModel = mongoose.model("variations", {
      "variations": [
          {
          "variationID": String,
          "custID": String,
          "projID": String,
          "variationTitle": String,
          "variationDesc": String,
          "variationStatus": String,
          "variationChargeable": String,
          "variationCost": String,
          "requireMaterial": String,
          "variationRequestor": String,
          "variationCreationDate": String,
          "variationImages": [
              {
              "imageId": String
              }
          ],
          "variationCategory": String
          }
      ]
  });
  </code></pre>
  
  <p>Anyone help me out?</p>
  
  <p>Thanks!</p>