I'm struggling to insert an object into an array of components. The components array is nested in a "scenes" array within a projects object. Below is the faulty route and a representation of the projects model, illustrating where all the fields are located. I've spent hours trying to pinpoint the problem without success.
{
"_id": {
"$oid": "5c01c26ec028296289f53b00"
},
"update": false,
"publishStatus": "draft",
"user": {
"$oid": "5bee30aed343c30016a664b5"
},
"projectName": "Griffith Uni",
"description": "sdaidjasidjasidjiasdjsad",
"scenes": [
{
"_id": {
"$oid": "5c01c29dc028296289f53b02"
},
"sceneName": "Persona Choose",
"components": []
},
{
"_id": {
"$oid": "5c01c2acc028296289f53b04"
},
"sceneName": "Home Menu",
"components": []
},
{
"_id": {
"$oid": "5c0208b16c550072b6b3b499"
},
"sceneName": "The Smiths",
"components": []
}
],
"lastUpdated": {
"$date": "2018-11-30T23:06:22.173Z"
},
"__v": 0
}
router.post(
"/projects/scenes/components/new",
passport.authenticate("jwt", { session: false }),
(req, res) => {
const newComp = new Components({
content: req.body.content
});
Project.findById(
{ _id: req.body.projectID },
Project.findByIdAndUpdate(
{ _id: req.body.sceneID },
{ $push: { components: newComp } },
() => res.json(newComp)
)
);
}
);