I have to delete the last 8 elements of an array saved in my mongodb database. With $pop I managed to delete the last, but not 8. How can I do that?
PostSchema.updateOne(
{ email: data.email },
{
$pop: {
gratitudeLog: 1,
},
},
(err, user) => {
if (err) {
res.sendStatus(404);
} else {
res.status(200).json(user);
}
}
);
I would appreciate some help.
Thanks