1

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

b.s
  • 2,409
  • 2
  • 16
  • 26
Nat
  • 679
  • 1
  • 9
  • 24
  • 1
    can't possible with find(), try aggregate() method see similar question and accepted answer [how to sort array inside collection record in mongoDB](https://stackoverflow.com/questions/13449874/how-to-sort-array-inside-collection-record-in-mongodb) – turivishal Apr 30 '21 at 16:14

0 Answers0