i using mongoose first time , declared session model below
var mongoose = require('mongoose'); var schema = mongoose.schema; var sessionschema = new schema({ session_id : string, users : [{ user_id : string, user_type : string, }], start_time : date }); var sessioninfo = mongoose.model('sessioninfo', sessionschema); module.exports = sessioninfo
now trying update users array, whenever user joined socket server same session id users detail should updated
below code that
newsession.update({session_id : sessionid}, {$push: {users : {user_id : userid, user_type : usertype} }}, {safe: true, upsert: true}, function(err,model){ console.log(err); });
but whenever client connects node js server below error
tue apr 28 2015 01:53:07 gmt+0530 (ist) connection accepted.
/home/rahulshr/node_modules/mongoose/lib/query.js:1878 oldcb(error, result ? result.result : { ok: 0, n: 0, nmodified: 0 }); ^ typeerror: object not function @ query.callback (/home/rahulshr/node_modules/mongoose/lib/query.js:1878:7) @ /home/rahulshr/node_modules/mongoose/node_modules/kareem/index.js:167:19 @ /home/rahulshr/node_modules/mongoose/node_modules/kareem/index.js:103:16 @ process._tickcallback (node.js:415:13)
i found root cause, instead of calling update instance of session schema (newsession in case) should call sessioninfo