Mongoose : using promises as parameters for other functions Mongoose : using promises as parameters for other functions mongoose mongoose

Mongoose : using promises as parameters for other functions


try this exec() returns promise.

serviceSchema.statics.getIdByName = function getIdByName(serviceName) {    return this.findOne({        name: serviceName    }).exec();}

Call getIdByName function

Service.getIdByName("facebook").then((data) => {    console.log(data)})


The answer to this is actually using async/await and and do var x = await Model.findOne().exec()

or any function that returns a promise, then you can use x anywhere in the code