Trying to create a simple system where users can review books but I keep getting an error of "push" is undefined. I've tried to push new reviews to the db many times but failed every time.
I have a mongoose model:
var WorkSchema = new mongoose.Schema({
title: String,
genre: String,
workType: String,
length: Number,
ageRange: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
manuscriptText: String,
workRating: [
{
reviewerName: String,
critique: String,
date: Date
}
],
ratingNumber: [Number],
ratingSum: {
type: Number,
default: 0
}
});
Here is my review post with all the commented out failed code:
// post route for getting the review
router.post('/:id', function(req, res) {
var critique = req.body.critique;
var reviewerName = req.user.username;
// find the right work associated with the critique
Work.findById(req.params.id, function(err, foundWork) {
if(err) {
console.log(err);
} else {
// foundWork.workRating.reviewerName.push(reviewerName);
// foundWork.workRating.critique.push(critique);
// foundWork.workRating.date.push(Date());
// foundWork.save();
// });
// }
// foundWork.update(
// {$push: {workRating: }
// }
// );
// {
// $push: {
// workRating: {
// reviewerName: reviewerName
// reviewerReview: critique
// }
// // ratingNumber: req.body.clickedValue,
// // $inc: {
// // ratingSum req.body.clickedValue
// // }
// }
// }
}
});
});
What the heck am I doing wrong to get these two values into that array?