Answer the question
In order to leave comments, you need to log in
How to make .then work inside a Promise?
How to make .then work inside a Promise ? The second find by tags no longer works because searchArr is not ready...
articleSchema.statics.list = function ({tag, sort, limit, skip}) {
return new Promise(function (resolve, reject) {
const Tag = mongoose.model('Tag');
let searchArr = [];
Tag.find({label: tag}, {label: false, updatedAt: false, createdAt: false, articleId: false, __v: false}).exec()
.then((findTags) => {
findTags.map((item, index) => {
searchArr.push(String(item._id));
});
return searchArr;
})
.then((searchArr) => {
return this
.find({
'tags': {
$in: searchArr
}
})
.sort('-' + sort)
.skip(parseInt(skip))
.limit(parseInt(limit))
.populate('tags')
.exec()
.then((Articles) => {
resolve(Articles);
console.log('Articles');
console.log(Articles);
})
//.catch(e => next(e));
})
//.catch(e => next(e));
//resolve(Articles);
});
};
Answer the question
In order to leave comments, you need to log in
If it's an Action, then $id is a query parameter. It is usually passed in the request uri and denoted in the routing template as {:id} .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question