I have this schema:
const SoundSchema = new Schema({
name: {
type: String,
required: true
},
minFrec: {
type: Number,
required: true
},
maxFrec:{
type: Number,
required: true
},
minInt:{
type: Number,
required: true
},
maxInt:{
type: Number,
required: true
},
category: {
type: String,
lowercase: true,
required: true,
enum: ["Hogar", "Naturaleza", "Conversación", "Ocio", "Lugares", "Ciudad"]
}
});
And I am trying to create this route to show all my items that match a certain category:
app.get("/sounds/:category", async (req, res) => {
const sounds = await Sound.find({ category: 'Ocio' }).sort({ name: 'asc'});
res.render("sounds/category", { sounds });
});
It does not work (returns an empty array) but it works if I filter by something without “enum” (name, minInt, etc).
I have done other routes that work, and I can find those items in mongo (db.sounds.find({category: "Ocio"}))
.