com-puter-tips/Technical-eBooks

Issue with document example for Interacting with MongoDB Using Mongoose

TheRealist908 opened this issue · 0 comments

On page 106, Creating More Documents walks us through how to create team records and then use the ids that are created and pass retrieve them to build the inserts into the employee documents. The source code example for function insertEmployees (pd, devops, acct, callback) {...} uses the team ids created from function insertTeams (e.g. pd._id, devops._id, and acct._id) and references them in when creating the new employees. The problem is, the arguments passed into the function devops and acct remain undefined. However, the pd argument ends up as an array with three models. So, i'm not sure how devops and acct are ever getting updated but when debugging, then continuously remain undefined.

To fix this, I changed the team id references to point to pd[0]._id (for the first employee), pd[1]._id (for the second employee), and pd[2]._id (for the third and fourth since they represent the same team). This was the only way I was able to get this to work.

I am unsure if that was the correct approach but I was able to finally insert into both teams and employees using this source code (after many hours trying different options out and using node-inspector).

Oh, and before I forget, this is an awesome collection of information. I really appreciate the solid explanations!