I have tried these methods and it does not seem to sort.
.sort("-remark.remarkdate")
.sort({"remark.remarkdate" : "-1" })
Here is my schema:
const mongoose = require('mongoose');
const {ObjectID} = mongoose.Schema.Types;
const accountSchema = new mongoose.Schema({
accounts:{type:ObjectID,ref:"Person"},
products:{type:ObjectID,ref:"Products"},
remark:[{
text:String,
remarkdate:{type:Date, default: Date.now}
}],
posteddate: {
type:Date,
default: Date.now
},
},
{ timestamps: true });
module.exports = mongoose.model("Account", accountSchema);
What am I missing? Thanks