What is the use case for IncrementSet and IncrementFrom?

What is the use case for IncrementSet and IncrementFrom? It feels like if you have the value for Set or From, you might as well just update the value directly to what you want rather than using an increment operator.

For example, if I want to increment the count by 1 and I know that the count should be at 5, I can use incrementSet 6, IncrementFrom 5, or i can just set count: 6… Am I missing something?

In both cases, it allows you to embed conditional logic in your increment operation if you don’t know the current value in the record. In your example, you are incrementing a single record and you know both the current value and the desired final value. These operations are for if you don’t know the current value across the records you need to update.

In the case of incrementFrom perhaps you have a version attribute and you only want to bump all the records with a current version of 2 → 3, but don’t want to increment records that are still on version 1 (or already on version 3).

In the case of incrementSet perhaps you have a version attribute and you want to increment all records by one version, up to the current version of 3. Here 1 → 2 and 2 → 3, but 3 and above do not get incremented.

These allow you to handle edge cases for incremental partial updates without needing to do complex record queries against your index.

Another important feature of these operations is idempotence, which isn’t guaranteed with the standard Increment and Decrement operators. Obviously, you get idempotence with a direct set, but it requires you to know the existing value in the records.