The following function fetches a collection from my database:
module.exports.getUserSubscriptions = function(id, callback) {
Subscription.find({user:id})
.sort({start_date: 'desc'})
.populate({
path:'plan',
model:'Plan'
})
.lean()
.exec(callback);
}
Regardless of how I call sort, I can't make it actually sort the data.
start_date is defined in the Subscription Schema like this:
start_date: {
type: Date,
default: Date.now
}
and looks like this when queried:
ISODate("2017-05-16T11:36:58.605Z")
I've tried adding the sort to the find query too with no effect. I've also tried using .sort("-start_date") but nothing I try makes any difference to the output.
Any suggestions would be greatly appreciated.
via Taintedmedialtd
No comments:
Post a Comment