I am just started learning Promises, i getting console result as [ Promise { pending } ] i want to Print the Exact result coming from the function, can anybody help me on this.
exports.listProjectRepos1 = (req, res)=> {
let pID = mongoose.Types.ObjectId(req.params.projectId);
console.log("User Id is ", req.user._id);
let query = {
userID: mongoose.Types.ObjectId(req.user._id),
projectID: pID
};
RepositoriesSchema.find(query).lean().then((repos)=> {
return repos
}).then((repos)=> {
let roots = repos.map(exports.populateCodestack1);
console.log(roots);// trying to Print the Results here
});
};
exports.populateCodestack1 = function (repo) {
return new Promise((resolve, reject)=> {
Promise.all([new Promise((resolve, reject)=> {
let codeId = repo.codeStack;
CodeStacksSchema.findOne({ID: codeId}).lean().exec(function (err, codeStack) {
if (codeStack) {
repo.stack = codeStack.name;
resolve(repo)
}
});
}),
new Promise((resolve, reject)=> {
let owner = mongoose.Types.ObjectId(repo.SCMAccount);
console.log("Owner Id is", owner);
ScmaAccount.findOne({_id: owner}).lean().exec(function (err, scm) {
if (scm) {
repo.type = scm.type;
resolve(repo);
}
});
})
]).then(function (result1) {
// console.log("Refresh Result",result);
resolve(result1);
})
})
};
I want to Print the output of the Function.