Closed npvn closed 10 years ago
You can't edit the selector by setting it to something else. In order to replace it completely, you will need to set it the arguments object: this.args[0] = newSelector
instead of selector = newSelector
. For an example, see selector rewriting in https://github.com/mizzao/meteor-partitioner.
An alternative approach is to delete selector.field
instead of selector = _.omit(selector, "field")
, which won't change the reference to the selector object.
Thanks for the thorough answer, @mizzao.
The problem I'm wanting to solve: I have a collection of orders. Each order has a native _id and a customized orderId (something like
S3-9446
). I want to prevent other developers from using the wrong selector (e.g.{_id: 'S3-9446'}
and{orderId: 's4LP7H6P5DAXrFLwo'}
are both wrong). I do this by pre-checking the selector and modify it if necessary: http://screencast.com/t/6lGnvQjLy7tKAs you can see in the screencast, although the selector is correctly edited, the result is still
undefined
. On server the code works normally and always return the desired object.Note: In the screencast,
App.isWREId
will return true if the argument is a customized id (likeS3-9446
).