A document's metadata contains only the Counters' names-list for this document.
Counter Values are not kept in the document's metadata, but in a separate location.
Therefore, changes like adding a new counter or deleting an existing counter trigger a document change,
while simply modifying the Counter Value does not.
Cumulative Counter Actions
- Counter value-modification actions are cumulative, the order in which they are executed doesn't matter.
E.g., It doesn't matter if a Counter has been incremented by 2 and then by 7, or by 7 first and then by 2.
- When a Counter is deleted, the sequence of Counter actions becomes non-cumulative and may require
Counters and Conflicts
Counter actions (for either name or value) almost never cause conflicts.
The only exception to this is concurrent
actions by multiple cluster nodes.
- Counter actions can be executed concurrently or in any order, without causing a conflict.
- You can successfully modify Counters while their document is being modified by a different client.
Counter actions can still be performed when their related documents are in a conflicted state.
Counters are designated to lower the cost of counting, but do come with a price.
- All the names of a document's Counters are added to its content, increasing its size.
- Counter values occupy storage space.
Be aware that the negligible amount of resources required by a few Counters,
may become significant when there are many.
A single document with thousands of Counters is probably an indication of a modeling mistake,
Counters Naming Convention
- Valid range: Signed 64-bit integer (-9223372036854775808 to 9223372036854775807)
- Only integer additions are supported (no floats or other mathematical operations).
Number of Counters Per Document
RavenDB doesn't limit the number of Counters you can create.
When a Counter is added to a document, RavenDB automatically sets a
HasCounters Flag in the document's metadata.
When all Counters are removed from a document, the server automatically removes this flag.