I currently have the following schema:
Schema({ _id: { type: Number, default: Math.floor(Date.now() / 1000) + 24 * 60 * 60 }, userID: { type: Number, require }, assignmentID: { type: Number, validate: { validator: function (v) { if (!v) { Promise.reject(false); } else { Assignment.findById(v, (assignmentErr, assignmentDoc) => { if(assignmentErr || !assignmentDoc){ Promise.reject(false); } else{ Promise.resolve(true); } }) } }, message: 'Invalid assignment ID.' } } The issue I am facing is that I keep getting warnings in the console that I am not handling the rejected promises. Also the document is saved in the database even though the promise is rejected.
The way I save the new document is the following:
schema.save((err, savedDoc) => { } How can I solve this issue or is there a better way to do complex validation like this?