0

I'm doing a project with node and using the mongoose

app.get('/', (req, res) => {
    Habbo.find({}).then((habbo) => {
        return res.json(habbo);
    }).catch((erro) => {
        return res.status(400).json({
            error: true,
            message: "Nenhum artigo encontrado!"
        })
    })
});

I'm just managing to make it show all the records in the database, I need it to show me only the last record

I've tried several ways but I'm not getting it, can someone help me?

  • 2
    see similar [question1](https://stackoverflow.com/questions/56821497/in-mongodb-what-is-the-most-efficient-way-to-get-the-first-and-last-document) and [question2](https://stackoverflow.com/questions/38975607/mongodb-get-first-and-last-document-in-aggregate-query) – turivishal Jun 23 '21 at 18:01
  • use sort and limit function of mongoose, sort in ascending or descending order and use limit(1) with mongoose – Shailendra Jun 23 '21 at 18:45

0 Answers0