流星collection.update permisions

Blo*_*kas 3 collections meteor

嗨,我不明白为什么这不起作用?

Notifications.update({'userId':Meteor.userId(), 'notifyUserId':notifyFriendId}, {$set: {read: 1}});
Run Code Online (Sandbox Code Playgroud)

我也有更新允许方法

Notifications = new Meteor.Collection('Notifications');

Notifications.allow({
  update: function(userId, doc) {
    return true;
  }
});
Run Code Online (Sandbox Code Playgroud)

出现错误:

Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403] 
Run Code Online (Sandbox Code Playgroud)

Aks*_*hat 6

要更新集合,您只能使用该文档_id.所以你需要先查询它

var docid = Notifications.findOne({'userId':Meteor.userId(), 'notifyUserId':notifyFriendId});
Notifications.update({_id:docid._id}, {$set: {read: 1}});
Run Code Online (Sandbox Code Playgroud)

这仅适用于在客户端上运行的代码.在服务器上,您可以像运行代码一样运行代码.