1

So in my MERN project in my router, I am trying to send some data so I can get afterwards on my react component so I can use that data.

But I get this error when I run my code: TypeError: Cannot read property 'status' of undefined

Here is my code:

  const Accomodation = require('../models/accomodation')
    Accomodation.findOne({email: req.session.passport.user}).lean().exec((err, user, res) => {
        if (err) {
          console.log(err, null);
        }  

        if (user) {
          res.status(200).send({
            message: user.accomcate
          })
      }
    })

});
Michael Kitas
  • 239
  • 1
  • 2
  • 14

1 Answers1

1

.exec accepts two arguments err and res , you are using three which is causing the error.

Bilal Hussain
  • 572
  • 6
  • 14