The .sort()
function doesn't seem to work for me at all, it doesn't sort whatever I do.
I display the output via Handlebars {{Book}}
router.get("/", (req, res) => {
Book.find({ _id: req.params.id })
.sort({ 'chapters.orderIndex': 1 }) //wont sort
.then(books => {
res.render("books/index", {
books: books
})
});
});
I Also tried:
.sort({ 'Book.chapters.orderIndex': 1 })
.sort({ 'Book.date': 1 })
.sort({ 'date': 1 }) //field from Book
.sort({ date: 1 })
and also tried asc
/desc
instead using 1
/-1
Any idea why .sort()
isn't working?