0

I have this function:

router.route('/banner/:_id')
    .post((req, res, next) => {
        console.log('got here');
        var r = req.body;
        // console.log(r.message);
        // console.log(req.params._id);
        try {
            Banner.findOne({_id: req.params._id}, (e, doc) => {
                console.log(doc);
                if (e) console.log(e);
                doc.time = r.time;
                doc.date = r.date;
                doc.technicalIssue = r.technicalIssue;
                doc.message = r.message;
                doc.save(e => console.log(e));
            })
        }
        catch (e) {
            console.log(e);
        }
        res.redirect('/admin');
    });

When I post to it I get this:

POST /admin/banner/5ac1574c734d1d4f8af95a69 302 41.225 ms - 56
{ partnersLogos: [],
    _id: 5ac1574c734d1d4f8af95a69,
    date: '1 May',
    time: '1 - 5pm',
    technicalIssue: '',
    message: 'test2',
    __v: 1 }
null

So I can see it finds the document needed. The problem is it doesn't save it. It's probably some stupid error, but I cannot see it anywhere. Any idea?

I'm using Express with Mongoose on mlab.

I tried mimicing this answer but something went wrong.

Banner model:

var mongoose = require('mongoose');
var bannerSchema = new mongoose.Schema({
    technicalIssue: String,
    time: String,
    date: String,
    partnersLogos: [],
});
module.exports = mongoose.model('banner', bannerSchema);
Alex Ironside
  • 4,658
  • 11
  • 59
  • 119

1 Answers1

0

I forgot to add the message field in my model.

Alex Ironside
  • 4,658
  • 11
  • 59
  • 119