title: How to use Group by with find in mongoose?
body: <p>I have collection named "listing" with fields such as <strong><code>metadata</code></strong> and <strong><code>status</code></strong>. metadata is a object containing <strong><code>user</code></strong> object inside and <strong><code>status</code></strong> is a string.</p>
  
  <p>The structure looks like this,</p>
  
  <blockquote>
    <p>{   "status": "Active",   "metadata": {
        "user": {
          "urlProfile": "",
          "averageRating": 5,
          "reviewCount": 2,
          "userId": "1244324"
        }   } }</p>
  </blockquote>
  
  <p>Now the status field have values such as <strong><code>"Active"</code></strong> and <strong><code>"Inactive"</code></strong>. I need to group by those status and filter by the userId. so i have a function inside the helper as follows,</p>
  
  <pre><code> query: function (model, conditon, options) {
              console.log(conditon, options);
              return new Promise(function (resolve, reject) {
                  options = options || {};
  
                  model.find(conditon, {}, options).exec(function (error, data) {
                      if (error) {
                          reject(error);
                      }
                      resolve(data);
                  })
              })
          }
  </code></pre>
  
  <p>Question is how can i pass the group by along with the user id and query the data needed. Right now my querying part looks like this,</p>
  
  <pre><code>return dbService.query(sellerModel, {
                      'metadata.user.userId': userIdRetrieved
                  }, {});
  </code></pre>
  
  <p>how can i pass the group by condition? i looked for sample, did not find any solution till now.</p>
  
  <p><strong>Sample Collection</strong>
  <a href="https://i.stack.imgur.com/Y1w4U.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y1w4U.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>[{
    "Status": "Active",
    "Results": {
      "user": {
        "urlProfile": "",
        "averageRating": 5,
        "reviewCount": 2,
        "userId": "1244324"
      }
    }
  }
  ,
  {
    "Status": "InActive",
    "Results": {
      "user": {
        "urlProfile": "",
        "averageRating": 5,
        "reviewCount": 2,
        "userId": "1244324"
      }
    }
  }]
  </code></pre>