流星扔扔IfSelectorIsNotId异常 [英] Meteor throws throwIfSelectorIsNotId exception

查看:133
本文介绍了流星扔扔IfSelectorIsNotId异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当运行一些代码时,Meteor会抛出一个throwIfSelectorIsNotId异常。我有两个客户端运行相同的代码,当第二个客户端运行相同的代码片段时抛出异常。

When running some code Meteor throws a throwIfSelectorIsNotId exception. I have two clients running the same code and the exception is thrown when the second client is running the same pice of code.

不知道这个异常是什么意思,以及为什么会被抛出。希望有人能够解释它。

Cant figure out what this exception means and why it is thrown. Hopefully someone will be able to explain it.

推荐答案

对于客户端的某些操作(自0.57版本以来,我认为是)。当执行更新操作时,例如

For certain operations on the client (since version 0.57 I think it was). When doing an update operation e.g

MyCollection.update({name:"John Doe"},{$set:{age:50}});

您需要在客户端将其拆分成两部分。 (仅在客户端上)

You need to split it into two parts, on the client. (Only on the client).

var doc_id = MyCollection.findOne({name:"John Doe"})._id;
MyCollection.update({_id:doc_id,{$set:{age:50}});

您需要通过 _id 首先再更新该文件。选择器只能是 _id update & 删除操作。

You need to find the document by the _id first then update that document. The selector can only be an _id for update & remove operations.

这是因为流星设计的安全风险,如果有客户端mongodb数据库,它可以在确定是否允许更新的同时在其他操作上任意地从服务器获取信息。它在Meteor 0.57中引入。

This is because of a security risk with meteor's design, if there were to be a client side mongodb database it could arbitrarily get information from the server on other operations while determining on whether to allow the update or not. It was introduced in Meteor 0.57.

这篇关于流星扔扔IfSelectorIsNotId异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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