Reputation: 181
I am using mongoose for the first time and declared my session model like 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 I am trying to update the users array, whenever user joined my socket server with the same session id users detail should get updated
Below is the code for 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 to the node js server I get 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 is not a function at Query.callback (/home/rahulshr/node_modules/mongoose/lib/query.js:1878:7) at /home/rahulshr/node_modules/mongoose/node_modules/kareem/index.js:167:19 at /home/rahulshr/node_modules/mongoose/node_modules/kareem/index.js:103:16 at process._tickCallback (node.js:415:13)
Upvotes: 0
Views: 559
Reputation: 181
I found the root cause, instead of calling update with instance of Session schema (newSession in this case) I should call it with SessionInfo
Upvotes: 1