let result = await User.find().skip(skipVar).limit(pageSize)
result.forEach((item) => {
if (item.events) {
item.events.sort((a, b) => {
const dateA = new Date(a.startDate).getTime();
const dateB = new Date(b.startDate).getTime();
return dateA - dateB;
});
}
})
const total=await User.countDocuments()
res.status(200).json({
status:'sucess',
count:total,
result
})