Commit 8d8a98af authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

asd

parent dcc19277
......@@ -71,28 +71,32 @@ const recommendPro = async (req, res) => {
_id: "$products.productId",
count: { $sum: 1 }
}
},
{
$sort: {
count: -1
}
},
{ $limit: 5 },
{
$lookup:
{
from: "products",
localField: "_id",
foreignField: "_id",
as: "product"
}
}
])
console.log('recommend=', recommend)
const filteredRecommend = recommend.filter((el) => String(el._id) !== String(productId))
console.log('filtering=', filteredRecommend)
filteredRecommend.sort(function (a, b) {
if (a.count > b.count) {
return -1;
}
if (a.count < b.count) {
return 1;
}
// a must be equal to b
return 0;
});
const finalrecommend= filteredRecommend.slice(0,4)
const array = finalrecommend.map(async (el) => {
const aa = await Product.findById(el._id)
return aa
})
const bb = await Promise.all(array)
res.json(bb)
// const array = filteredRecommend.map(async (el) => {
// const aa = await Product.findById(el._id)
// return aa
// })
// const bb = await Promise.all(array)
res.json(filteredRecommend)
} catch (error) {
console.log('error in order ', error)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment