find no req.body using populate

Asked

Viewed 110 times

0

Controller

async index(req, res) {
        const avali = await Avaliacao.find(req.body)
        .populate('Time').exec((time, err) => {
            console.log(`Para retorna tudo ${time}`)
        })

    return res.send(avali)
},

Model

const AvaliacaoShema = new Schema({
responsavel: {
    type: String
},
time: [{
    type: Schema.Types.ObjectId,
    ref: 'Time',
}]
})
module.exports = model('Avaliacao', AvaliacaoShema)

I’m trying to give a req.body, but in the time field does not return the value of the object with the expected.

1 answer

1


Try to make the following adjustments:

  1. Check that the parameter for the Evaluation search is returning correctly;
  2. place the populate path value, exactly equal ('time') to the attribute in the Mongoose schema.
  3. If it still doesn’t work, send more details about the parameter you are sending through the body, about what purpose and etc.

    async index(req, res, next) {
    let param = { responsavel: req.body.responsavel }
    const avali = await Avaliacao.find(param)
      .populate({ path: 'time' })
      .exec()
      .then(time => {
        console.log("Para retorna tudo" + time)
      })
    res.send(avali)}
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.