I'm trying to update a collection in my meteor app and am getting the following error:
update failed: 403 -- Access denied. Can't replace document in restricted collection.
In the server I have the following code:
Songs = new Meteor.Collection("songs");
PlayLists = new Meteor.Collection('playlists');
PlayChannels = new Meteor.Collection('playchannels');
Meteor.publish('songs', function () {
return Songs.find();
});
Meteor.publish('playlists', function () {
return PlayLists.find();
});
Meteor.publish('playchannels', function () {
return PlayChannels.find();
});
Meteor.startup(function () {
Songs.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; },
fetch: function () { return true; }
});
PlayChannels.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; },
fetch: function () { return true; }
});
PlayLists.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; },
fetch: function () { return true; }
});
});
And I'm making the call as follows:
PlayChannels.update({_id: Session.get('playchannel')},{current:Session.get('current')});
What am I doing wrong?
What was wrong was the call. The correct way to do it is:
PlayChannels.update({
_id: Session.get('playchannel')
}, {
$set: {
current: Session.get('current')
}
})
the fetch option of allow should return an array, not a boolean, or just remove it completely. I think this should solve it, because in the same scenario I had allow fail because fetch was returning a boolean, thus not taking in the allowance for update.
Songs.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; }
});