This is the error that I am getting in my terminal…
“TypeError: Cannot read properties of undefined (reading ‘create’)”
Says that the problem is stemming from my ‘comment-controller.js’ file, where it says ‘Comment.create(body)’ (line 2)
console.log(body);
Comment.create(body)
.then(({ _id }) => {
return Pizza.findOneAndUpdate(
{ _id: params.pizzaId },
{ $push: { comments: _id } },
{ new: true }
);
})
.then(dbPizzaData => {
if (!dbPizzaData) {
res.status(404).json({ message: 'No pizza found with this id!' });
return;
}
res.json(dbPizzaData);
})
.catch(err => res.json(err));
}
}
module.exports = commentController;
This is the Schema for the comment
const CommentSchema = new Schema({
writtenBy: {
type: String,
},
commentBody: {
type: String,
},
createdAt: {
type: Date,
default: Date.now,
},
});
const CommentModel = model("Comment", CommentSchema);
module.exports = CommentModel;
I’m using insomnia to create the test comment, which is this
{
"writtenBy": "Cade",
"commentBody": "This is a test comment"
}
I saw that someone posted about this but I looked to see if their solution would work for mine but from my eyes I see that I have that syntax layout, so I’m confused if it may be something else or I’m just blind and I can’t see it for my self.