I'm just asking myself why my template returns null when it shouldn't.
This is my findOne :
await this.findOne({name}, async (template) => {
console.log(template);
if (template) return cb(new Error('Template already exists'));
And I'm sure that it should returns me the error Template already exists, because the document with this name exists in my DB.
Someone know why?
Just call .exec()
at the end to get the promise and use await to get the value like this
const template = await this.findOne({name}).exec();
// do something here with template
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.