Meteor throws throwIfSelectorIsNotId exception

浪尽此生 提交于 2019-12-11 03:43:22

问题


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.


回答1:


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}});

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.

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.



来源:https://stackoverflow.com/questions/16687453/meteor-throws-throwifselectorisnotid-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!