I am trying to list the documents in my level collection by the lowest level to the highest, but that is not working. My code is
const lvl = await Level.find({}).sort({level: 1});
for the filter, and I list it over here:
lvl.forEach(entry => {
embed.addFields({ name: `Level ${entry.level}`, value: `Xp Required: ${entry.xp}`});
})
The code for the level schema is:
const mongoose = require("mongoose");
const LevelSchema = new mongoose.Schema({
level: mongoose.Schema.Types.String,
xp: mongoose.Schema.Types.String,
});
module.exports = mongoose.model("levels", LevelSchema);
This code is working completely fine, the only issue is that it comes in the order that the documents are in the collection, and not by the lowest level to the highest like I want it to. I did what the documentation told me to do in the .sort({level: 1}) part, but that didn't change anything either.