Whenever I try to push into the pathItem array, the response is an empty array. What is happening?
const categories = await Cars.find().distinct("bodytype");
let pathItem = [];
categories.forEach(async (element) => {
const countQuery = await Cars.countDocuments({
bodytype: element,
});
const numberOfPages = Math.ceil(countQuery / 12);
for(let count=1; count<=numberOfPages; count++) {
const carPath = {paths: { cartype: element, pages: count }}
pathItem.push(carPath)
}
});
console.log(pathItem) // this returns an empty array
Promise.all