未捕获错误:不允许。不受信任的代码只能通过ID更新文档。 [403] [英] Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403]

查看:242
本文介绍了未捕获错误:不允许。不受信任的代码只能通过ID更新文档。 [403]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误,但它没有指定哪个代码行有错误。
有什么办法,我可以缩小哪些代码我需要关注?

I have this error but it does not specify which code line is faulty. Is there any way I can narrow down which codes I need to focus on?

不确定是否有相关问题,但是当我提交文档时,它应该能够识别我的 user.username ,但是当html显示 {{author}} 时它会空白。

Not sure if its a related problem, but when I submit a doc and its supposed to recognize my user.username, but it comes out blank when html displays {{author}}.

集合的代码(公共/服务器的共享文件夹)如下:

The code for the collection (shared folder for both public/ server) is as below:

var post = _.extend(postAttributes, {
  userId: user._id, 
  author: user.username
});




感谢任何帮助!



更新:


Update:

将UserAccount代码移入服务器文件夹。
模拟调用'postInsert'时的异常
匹配错误:字段消息中的未知键

New error message after shifting the UserAccount codes into server folder. Exception while simulating the effect of invoking 'postInsert' "Match error: Unknown key in field message"

推荐答案

您在客户端上有一个代码,它使用的不是 _id 作为其查询运算符来更新文档。

You have code on the client side that uses something that isn't an _id as its query operator to update a document.

无法使用这样的查询在客户端上更新。你可以在服务器上做这些。

It is not possible to update on the client with a query like this. You can do these on the server though.

所以如果你有这样的代码,你运行它,而不会抛出你得到的错误:

So if you have code like this somewhere, you run it without throwing the error you're getting:

MyCollection.update({ someName: someValue }, {$set:{something:true}});

您可以:

var doc = MyCollection.findOne({ someName: someValue });
MyCollection.update({ _id: doc._id }, {$set:{something:true}});

在这里您明确定义要更新的文档。要找到这个代码,你可能想要查找 .update 中可以在客户端运行的任何东西。

Here you explicitly define which document you would like to update. To find this code you might want to look for anything with .update in it that can run on the client side.

这篇关于未捕获错误:不允许。不受信任的代码只能通过ID更新文档。 [403]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆