I have a function like this, which should return a schema after query is complete. I am not understanding why this function is always returning undefined value.
var loadSchema = function(className) {
var query = schemaModel.findOne({className: className})
var promise = query.exec()
promise.then(function(schema){
console.log(schema)
return schema
}).then(null, console.log)
}
I also tried to return a whole promise from function but still I cannot get the value. Like this
var loadSchema = function(className) {
var query = schemaModel.findOne({className: className})
var promise = query.exec()
return promise.then(function(schema){
console.log(schema)
return schema
}).then(null, console.log)
}
Can Anyone please tell me the flow of this program. I have watched other similar questions in stackoverflow but I cannot get the whole idea behind this.
Edit: This is the code where I am using this value.
module.exports.getSchema = function(req) {
var className = req.params.classname
var schema = loadSchema(className)
console.log(schema)
return schema
}