Mongoose - Query Latest Document
I want to query for the latest document in my database. I wrote following function for it but it doesn't return the latest entry, instead it just returns the first one in the db. I
Solution 1:
sort()
and limit()
are in the wrong order; you're limiting BEFORE your sort backward. Change it to:
SmallHistory.findOne().sort({ date: -1 }).limit(1).exec((err, data)
Post a Comment for "Mongoose - Query Latest Document"