I'm in the learning process of the MEAN stack and I'm using meanjs.org as a starting point and used it to generate scaffolding for a new object.
I'm trying to figure out how to implement the correct pattern in the client Angular code in addition to the server code.
Assume I have a collection of meetings and each meeting contains an array of participant objects (by reference, not embedded).
Therefore my javascript object may look like this:
meeting: {
_id: 123456,
location: "Room 222",
startDatetime: ....,
endDatetime: ....,
participants: [
{ _id: 33333 },
{ _id: 44444 }
]
}
If I wanted to add a participant (and assuming I have the id of that new participant), I could implement this in various ways:
- In an angular controller handle the addition to the participants array and just "push" the new id onto the array. Then called the typical REST update api (in the mean stack a service/ng-resource) to handle to the update. Then on the server (mongoose) be able to handle this by taking the added entry in the array and call the appropriate function to add a participant.
- Have a separate REST function to handle adding a participant and implement similar to #1.
- Some other way that keeps things simple and clean.
What is the recommended way (recommended from the MEAN architecture or from a RESTful architecture or from a mongoose/MongoDB perspective) to implement this?