问题
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