Meteor Update Collection - Unavailable Error: Not Allowed. Invalid code can only update documents by ID. [403]

I study Meteor and stumbled upon this situation; I followed the Meteor textbook on plus topics. the code is exactly the same as in the video, the collection is updated, but in my browser it shows this error:

Unfixed error: not resolved. Invalid code can only update documents by ID. [403]

The code is here:

Template.person.events({ 'click': function (e, t) { Session.set("edit-"+ t.data._id, true); }, 'keypress input': function(e,t){ if(e.keyCode === 13){ var docid = Session.get("edit-"+ this._id); People.update(t.data, {$set: {name: e.currentTarget.value}}); Session.set("edit-"+ t.data._id, false); } } }); 
+8
javascript collections meteor
source share
2 answers

For code that runs on the client / browser side, you can only use the _id field as a request. On the server, you can run it as you wish.

Change your code to get the document first, and then use its _id to update.

 var person = People.findOne(t.data); People.update({_id: person._id}, {$set: {name: e.currentTarget.value}}); 

I assume t.data is some kind of query? If its _id try using {_id: t.data as a query. In any case, as long as the update selector only uses _id , this should be fine.

The reason this could affect the tutorial that you are following is because this change was introduced recently to block security.

+16
source share
  Template.person.events({ 'click': function (e, t) { Session.set('edit-' + t.data._id, true); }, 'keypress input' : function(e, t) { if (e.keyCode == 13) { People.update(t.data._id, { $set: { name: e.currentTarget.value }}); Session.set('edit-' + t.data._id, false); } } }); 
0
source share

All Articles