gpt4 book ai didi

collections - meteor collection.update权限

转载 作者:行者123 更新时间:2023-12-01 10:00:13 36 4
gpt4 key购买 nike

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

Notifications.update({'userId':Meteor.userId(), 'notifyUserId':notifyFriendId}, {$set: {read: 1}});

我也有更新允许方法

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

Notifications.allow({
update: function(userId, doc) {
return true;
}
});

出现错误:

Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403] 

最佳答案

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

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

这仅适用于在客户端上运行的代码。在服务器上,您可以按原样运行代码。

关于collections - meteor collection.update权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17251591/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com