arrays - Getting an app-crashing Mongo error after the query succeeds -


the insert succeeds , after app crashes, it's in db.

schema:

/**  * section schema  */ var sectionschema = new schema({   name: {     type: string,      required: true   } });  /**  * report schema  */ var reportschema = new schema({   created: {     type: date,     default: date.now   },   title: {     type: string,     default: '',     trim: true,     required: 'title cannot blank'   },   sections: [sectionschema],   user: {     type: schema.objectid,     ref: 'user'   } });  mongoose.model('report', reportschema); 

controller

/**  * create report  */ exports.create = function (req, res) {   var report = new report(req.body);   report.user = req.user;    report.sections = [];    // going on each name of sections , creating empty object each of them    req.body.sections.foreach(function (section) {      report.sections.push({        name: section      });    });   console.log(report);    report.save(function (err) {     if (err) {       return res.status(400).send({         message: errorhandler.geterrormessage(err)       });     } else {       res.json(report);     }   }); }; 

error:

/home/binny/programming/project/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:779       catch(err) { process.nexttick(function() { throw err}); }                                                  ^  typeerror: self[i].emit not function     @ eventemitter.notify (/home/binny/programming/project/node_modules/mongoose/lib/types/documentarray.js:214:15)     @ emittwo (events.js:92:20)     @ eventemitter.emit (events.js:172:7)     @ model.document.(anonymous function) [as emit] (/home/binny/programming/project/node_modules/mongoose/lib/document.js:88:42)     @ /home/binny/programming/project/node_modules/mongoose/lib/model.js:229:11     @ /home/binny/programming/project/node_modules/mongoose/lib/model.js:139:7     @ /home/binny/programming/project/node_modules/mongoose/node_modules/mongodb/lib/collection.js:479:5     @ /home/binny/programming/project/node_modules/mongoose/node_modules/mongodb/lib/collection.js:633:5     @ /home/binny/programming/project/node_modules/mongoose/node_modules/mongodb/lib/bulk/unordered.js:469:9     @ resulthandler (/home/binny/programming/project/node_modules/mongoose/node_modules/mongodb/lib/bulk/unordered.js:416:5)     @ /home/binny/programming/project/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:778:13     @ callbacks.emit (/home/binny/programming/project/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:95:3)     @ null.messagehandler (/home/binny/programming/project/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:249:23)     @ socket.<anonymous> (/home/binny/programming/project/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:262:22)     @ emitone (events.js:77:13)     @ socket.emit (events.js:169:7)     @ readableaddchunk (_stream_readable.js:146:16)     @ socket.readable.push (_stream_readable.js:110:10)     @ tcp.onread (net.js:523:20) 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -