Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addSponsor: async function (_id) {
- try {
- let val = await companyModel.findById(_id);
- if (val._id == _id) {
- console.log(val); //object is defined!
- this.sponsors.push(val) //object is undefined
- }
- } catch (err) {
- console.log(err)
- }
- },
- $ node ./mongoose/collections/skaters/models/skaterModel.js
- { _id: 5c489f46d7a825e15d41ae18, name: 'Zero' }
- TypeError: Cannot read property 'push' of undefined
- at Object.addSponsor (C:UsersJonasDesktopskaterDBmongoosecollectionsskatersmodelsskaterModel.js:47:31)
- at <anonymous>
- at process._tickCallback (internal/process/next_tick.js:189:7)
Add Comment
Please, Sign In to add comment