To use Node Sequelize findOne to find the latest entry, we order the result by createdAt
in descending order.
For instance, we write
model.findOne({
where: { key },
order: [["createdAt", "DESC"]],
});
to call findOne
with order
set to an array [["createdAt", "DESC"]]
to order the result by createdAt
in descending order to get the latest result.