3

I have an Express application with Mongoose. I have a model

var AttendeeSchema   = new Schema({
    name: String,
    registered: Boolean
});

var EventSchema   = new Schema({
    name: String,
    description: String,
    attendees : [AttendeeSchema],
    created: { type: Date, default: Date.now },
    updated: { type: Date, default: Date.now }
});

The code for creating an event is:

router.route('/:event_id')
    .get(function(req, res) {
        Event.findById(req.params.event_id, function(err, event) {
            if (err)
                res.send(err);
            res.json(event);
        });
    })

    .put(function(req, res) {
        Event.findById(req.params.event_id, function(err, event) {

            if (err)
                res.send(err);

            event.name = req.body.name;
            event.description = req.body.description; 
            event.attendees: req.body.attendees;

            event.save(function(err) {
                if (err)
                    res.send(err);

                res.json({ message: 'Event updated successfully!' });
            });

        });
    })

The code for updating an event is:

router.route('/:event_id')    
    .put(function(req, res) {
        Event.findById(req.params.event_id, function(err, event) {

            if (err)
                res.send(err);

            event.name = req.body.name;
            event.description = req.body.description; 
            event.attendees: req.body.attendees;

            event.save(function(err) {
                if (err)
                    res.send(err);

                res.json({ message: 'Event updated successfully!' });
            });

        });
    })

The problem is that events are being created successfully however when I try to update an event, it only updates the event name and description, but not changes to the attendees name or registered status. I also noticed that the version is not updated from "__v0" to "__v1"

Anyone some hints as to why I cannot update attendee specific information with the above code?

1
  • 2
    I assume the code event.attendees: req.body.attendees; is a typo and you meant it to be event.attendees = req.body.attendees;? Commented Apr 28, 2015 at 21:51

1 Answer 1

2

It looks like you need a = where you have a : ;)

event.attendees: req.body.attendees;
Sign up to request clarification or add additional context in comments.

1 Comment

Oh boy, I have been looking at this for over 3 hours. You are fully correct, now it is updating perfectly. Thanks!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.