这是我的学生模式:
var studentSchema = new mongoose.Schema({
name: String,
id: Number,
studmobil: Number,
email: String,
address: String,
isadult: Boolean,
isparent: Boolean,
date_of_join: {
type: Date,
default: Date.now
},
date_of_birth: Date,
father_name: String,
mother_name: String,
parentmob: Number,
parentemail: String,
rank:{
type: mongoose.Schema.Types.ObjectId,
ref: "Rank"
},
graduated: {
type: Boolean,
default: false
},
payments: [
{
payment_type: String,
amount: Number,
payment_date: Date
}
]
});
我正在尝试根据日期(最新的顺序)以降序对我的付款数组进行排序。这是我尝试使用的代码:
Student.findById(req.params.id).sort({"payments.payment_date": -1}).populate("rank").exec(function(err, foundstud) {
console.log(foundstud)
});
这是我得到的输出:
payments:
[ { _id: 5b7c24f2b3baa30ba965e55b,
payment_type: 'Tests',
amount: 600,
payment_date: 2018-08-08T00:00:00.000Z },
{ _id: 5b7c2502b3baa30ba965e55c,
payment_type: 'Membership',
amount: 1000,
payment_date: 2018-08-21T00:00:00.000Z } ],
数组仍按插入顺序排列。我缺少什么?