Skip to content

Instantly share code, notes, and snippets.

@astrotars
Created January 16, 2013 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrotars/4549233 to your computer and use it in GitHub Desktop.
Save astrotars/4549233 to your computer and use it in GitHub Desktop.
extract id from clients array
clientSchema.pre('remove', function(next) {
// clean up dependencies
Sweepstakes.remove({client_id: this._id}).exec();
Submission.remove({client_id: this._id}).exec();
// remove client id from users
User.update({clients: {$in: [this._id]}}, {$pull: {clients: this._id}}, function(err, numAffected) {
if (err)
console.log(err);
console.log('NUMBER OF ROWS AFFECTED: ', numAffected);
next();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment