I\'m trying to add a subdocument to a parent schema with Mongoose and MongoDB however I\'m being thrown the following error:
TypeError: User is not a constru
JavaScript is case sensitive about the variable names. You have User
model and the User
result with the same name.
Your code will work with the following change :
User.findById(id , function (err, user) {
/* ^ use small `u` */
if (err) return handleError(err)
/* rest of your code */
Also keep in mind that further in your code you are declaring another variable named user
. You will need to change that to something different.