title: Nodejs - Cannot read property then of undefined
body: <p>I'm getting this error when executing the following code:</p>
  
  <pre><code>getAggregatedRatings(query).then(ratings=&gt;{
      if(ratings){
          return res.json(ratings);
      }else{
          return res.send(200);
      }        
  }).catch((error)=&gt;{
      return res.send(500); 
  });
  
  function getAggregatedRatings(query){
      movieRating.aggregate(query)
      .exec((err, ratings)=&gt; {
          if (err || !ratings) {
              return Promise.reject(err);
          }
          else {
              return Promise.resolve(ratings);
          }
      });
  }
  </code></pre>
  
  <p>Please note that 'getAggregatedRatings' returns the query results as expected.
  Please advise what I'm doing wrong.</p>