It is not necessary to be clean, it must be idempotent . In practice, this is basically the same.
In addition, it should only be idempotent when viewed outside of the STM: if the only side effect that you produce is recorded in some other link or (I think) sending to the agent, this operation will be carried out as long as your transaction will not succeed.
It is also not that it should be any of these things: simply, if your update function is not clean, the results may not be what you expect.
Edit: dosync docs tell you that any expressions in the body can be executed more than once. You cannot start alter without running dosync , so it looks as if you have all the documents you need. What would you like to change?
source share