when attempting save document error thrown:
/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/utils.js:98 process.nexttick(function() { throw err; }); ^ typeerror: _this[i].emit not function @ eventemitter.notify (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/lib/types/documentarray.js:238:18) @ emitone (events.js:82:20) @ eventemitter.emit (events.js:169:7) @ document.(anonymous function) [as emit] (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/lib/document.js:93:44) @ eventemitter.<anonymous> (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/lib/schema/embedded.js:31:15) @ emittwo (events.js:92:20) @ eventemitter.emit (events.js:172:7) @ model.document.(anonymous function) [as emit] (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/lib/document.js:93:44) @ /users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/lib/model.js:227:11 @ /users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/lib/model.js:135:7 @ /users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/collection.js:504:5 @ /users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/collection.js:666:5 @ handlecallback (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/utils.js:96:12) @ /users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/bulk/unordered.js:473:9 @ handlecallback (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/utils.js:96:12) @ resulthandler (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/lib/bulk/unordered.js:420:5) @ commandcallback (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:1246:9) @ callbacks.emit (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:119:3) @ null.messagehandler (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:397:23) @ socket.<anonymous> (/users/home/documents/web/thp/modules/thp_db/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:302:22) @ emitone (events.js:77:13) @ socket.emit (events.js:169:7) @ readableaddchunk (_stream_readable.js:153:18) @ socket.readable.push (_stream_readable.js:111:10) @ tcp.onread (net.js:536:20)
code leading save looks this:
var db = req.app.locals.db; var league = new db.league(); // league populated here // ================ // give league _id (auto increment) // ================ db.counter.findbyidandupdate('league', { $inc: { n: 1 } }, { new: true }, function(err, counter){ if(err) return log.error('league _id set error', err); league._id = counter.n; // ================ // db: code runs here // ================ league.save(function(err, new_league) { // not reach here! if (err) { log.error('league db entry error:', err); return res.status(200).end('error creating league'); } console.log('saved league', util.inspect(new_league, false, null)); res.status(200).end('thank you'); }); } );
strange thing worked fine last night, , unless sleepwalked , logged in, nothing changed.
the db
variable collection of models.
any appreciated.
turns out error thrown depending on inputs of submission form filled out. haven't time determine @ moment, update here when do.
update: league
var populated json object parsed incoming form data. 1 of properties thoughtlessly called .on
, fooling standard event listening notation .on
. silly mistake! is.
Comments
Post a Comment