Categories
JavaScript Answers

How to use Node Sequelize findOne to find the latest entry?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.