Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to query the database for getting the last entry using URI/URL params? #2

Open
akibrk opened this issue Feb 23, 2019 · 1 comment

Comments

@akibrk
Copy link

akibrk commented Feb 23, 2019

//this is in the app.js file 
app.get('/api/user/last', (req, res)=>{
    User.getLastEntry((err, user)=>{
        if(err) throw err;
        res.json(user);
    });
});
//this is in the users.js file (mongoose model)
module.exports.getLastEntry = (callback)=>{
    User.find(callback).sort({'_id':-1}).limit(1);
}

I don't know how to use the params to get the last entry so using this instead.
I don't know where else to ask you about it. Thank you for the awesome lessons.

@ThePigStupo
Copy link

Why did you ask here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants