title: Cascade style delete in Mongoose
body: <p>Is there a way to delete all children of an parent in Mongoose, similar to using MySQLs foreign keys?</p>
  
  <p>For example, in MySQL I'd assign a foreign key and set it to cascade on delete. Thus, if I were to delete a client, all applications and associated users would be removed as well.</p>
  
  <p>From a top level:</p>
  
  <ol>
  <li>Delete Client</li>
  <li>Delete Sweepstakes</li>
  <li>Delete Submissions</li>
  </ol>
  
  <p>Sweepstakes and submissions both have a field for client_id. Submissions has a field for both sweepstakes_id, and client_id.</p>
  
  <p>Right now, I'm using the following code and I feel that there has to be a better way.</p>
  
  <pre><code>Client.findById(req.params.client_id, function(err, client) {
  
      if (err)
          return next(new restify.InternalError(err));
      else if (!client)
          return next(new restify.ResourceNotFoundError('The resource you requested could not be found.'));
  
      // find and remove all associated sweepstakes
      Sweepstakes.find({client_id: client._id}).remove();
  
      // find and remove all submissions
      Submission.find({client_id: client._id}).remove();
  
      client.remove();
  
      res.send({id: req.params.client_id});
  
  });
  </code></pre>