Building a collaborative app in Meteor. I am having issues with adding a user to a session. When i call my method "addUserToSession" and pass the relevant IDs, i get this error.
Exception while simulating the effect of invoking 'addUserToSession' TypeError: Cannot read property 'editors' of undefined(…) TypeError: Cannot read property 'editors' of undefined
I want this to happen ;
- User A starts a session.
- Sends the link to user B
- User B goes to the URL
- User B has their ID added to the session record in mongo
- Client gets the JSON in the record and updates DOM stuff.
I think it might be something to do with how i'm subscribing to the DB. Any help would be great!
Router.js
//if hit a URL with an ID
//set id session var and render sessionGrid
FlowRouter.route('/tides/:_id', {
name: 'oceanSession',
subscriptions: function(params) {
console.log("subscribe to sessions");
Meteor.subscribe('sessions');
Meteor.subscribe('myCollabs');
},
action: function(params) {
Session.set('id', params._id);
Meteor.call("addUserToSession", Meteor.userId(),Session.get('id'));
//console.log('session id set ' + Session.get('id'));
BlazeLayout.render('main', {
stuff: "sessionGrid"
})
}
});
shared/main.js
addUserToSession:function(userId, sessionId){
console.log(userId + " to be added to " + sessionId);
var editorArray = Sessions.findOne(sessionId)["editors"];
console.log(editorArray);
//Sessions.update({_id: sessionId}, {$push:{editors:userId}});
}
this doesn't behave and console gets
Exception while simulating the effect of invoking 'addUserToSession' TypeError: Cannot read property 'completed' of undefined(…) TypeError: Cannot read property 'completed' of undefined