Answer the question
In order to leave comments, you need to log in
How to return value from collection.find()?
var shortLinks = [];
Link.find({}).exec(function (err, links) {
if (err) {
console.log(err);
} else {
links.map(link => {
shortLinks.push(link.shortLink);
});
}
});
console.log(shortLinks); // тут массив пустой
Answer the question
In order to leave comments, you need to log in
exec() will return a Promise and process it.
var shortLinks = Link.find().exec();
// ...
shortLinks.then(function(links){
// work with links
}, function(err){
// some error
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question