diff --git a/models/User.js b/models/User.js index 0d88f2d..343ddf0 100644 --- a/models/User.js +++ b/models/User.js @@ -22,15 +22,10 @@ UserSchema.plugin(passportLocalMongoose); UserSchema.plugin(uniqueValidator); UserSchema.pre('remove', async function () { - await this.model('TodoList') + const lists = await this.model('TodoList') .find({ user: this._id }) - .remove() - .exec(); - - await this.model('Todo') - .find({ user: this._id }) - .remove() .exec(); + await Promise.all(lists.map(list => list.remove())); }); UserSchema.methods.generateJwt = function () {