We are trying to figure out how get the data from the database but the result get "null"
the model
const mongoose = require("mongoose");
const ClubSchema = new mongoose.Schema({
nomClub: String,
classement: String,
dateMatch: String,
classementDB: String,
logo: String,
adversaire: String,
});
const SportSchema = new mongoose.Schema({
nom: String,
clubs: [ClubSchema],
});
module.exports = mongoose.model("sport", SportSchema);
and the back
getSportAdversaire: (req, res) => {
Sport.findOne({ "clubs.nomClub": "Stade Rennais" }, (err, data) => {
if (err) {
console.log(err);
res.json({ message: "une erreur s'est produite" });
} else {
res.json(data);
console.log(data);
}
});
},