Here is part of my router:
if (limit <= 100) {
let id = jwt.verify(req.cookies.tokenlogin, config.get('jwtSecret')).userId
const results = await User.paginate({ $and: [{ _id: { $ne: id }, fullname: { $regex: search, $options: '-i' } }] },
{ page: page, limit: limit, customLabels: myCustomLabels, lean: true, select: '-email -password' });
let paginator = results.paginator;
let arrayRes = results.items;
await arrayRes.forEach(async (current, i) => {
await User.findOne({ _id: id }, async (er, rs) => {
current['followed'] = await rs.followings.includes(current.id);
})
})
res.status(200).json({ items: arrayRes, paginator: paginator })
}
I used await, but it does not work, server always sent not updated array to the client. How can i sent modified array in my response?