0

This is my schema:

let ORDER = new Schema({
    playername:String,
    serverUID:String,
    amount: Number,
    ADMIN_UID: String,
    status: Boolean,
    objid:Array,
})

I need to sort by ServerUID, then sort by objid and status is true, then calculate each amount. pls help me! I really don't know how to work with data!

this is my first time asking question on the platform, if I have some ignored and impolite please forgive me!

Jeremy Wu
  • 11
  • 1

1 Answers1

0

You can sort when reading data from MongoDB using .sort() function of JS. Here is the code. As you want to sort it using serverUID so, I set its value to 1.

ORDER.find(function(err,result){
        if (!err){
            res.send(result);
        }else{
            res.send(err);
        }
    }).sort({serverUID: 1});

I

Zohaib Amir
  • 221
  • 2
  • 8