//Various RQL expressions sent to the server using counter()
//Returned Counter value is accumulated
const rawquery1 = session.advanced
.rawQuery("from products as p select counter(p, \"ProductLikes\")")
const rawquery2 = session.advanced
.rawQuery("from products select counter(\"ProductLikes\") as ProductLikesCount")
const rawquery3 = session.advanced
.rawQuery("from products where PricePerUnit > 50 select Name, counter(\"ProductLikes\")")
//An RQL expression sent to the server using counterRaw()
//Returned Counter value is distributed
const query = session.advanced
.rawQuery("from users as u select counterRaw(u, \"downloads\")")
Counters and Revisions
A document revision stores all the document Counters'
names and values when the revision was created.
Stored Counter Values: Accumulated
A revision stores a Counter's value as a single sum, with no specification of the Counter's value on each node.
Revisions-creation can be initiated by Counter-name modification.
When the Revisions feature is enabled, the creation or deletion of a Counter initiates the creation of a new document revision.
Counter value modifications do not cause the creation of new revisions.
Counters and Smuggler
Smuggler is a DocumentStore property, that can be used
to export chosen
database items to an external file or to import
database items from an existing file into the database.
Transferred Counter Value: Distributed
Smuggler transfers the entire series of values that the different nodes maintain for a Counter.
To make Smuggler handle Counters, use DatabaseItemType entities to import or export.
Counters and the Backup task
There are two backup types: logical-backup and snapshot.
Both types store and restore all data, including Counters.
Both types operate as an ongoing backup routine, with a pre-set time schedule.
Logical Backup: Backed-up Counter values: Distributed
A logical backup is a higher-level implementation of Smuggler.
As with Smuggler, Counters are backed-up and restored including their values on all nodes.
A snapshot stores all data and settings as a single binary image.
All components, including Counters, are restored to the exact same state they've been at during backup.
Counters and the External Replication task
The ongoing external replication task replicates all data, including Counters.
Replicated Counter Value: Distributed
Counters are replicated along with their values on all nodes.
Replication can be initiated by both Counter-name updateandCounter-value modification.
Counters and the ETL task ETL is used to export data from RavenDB to an external (either Raven or SQL) database.
SQL ETL is not supported.
Counters cannot be exported to an SQL database over SQL ETL.
Export can be initiated by both Counter-name updateandCounter-value modification.
Exported Counter Value: Distributed
Counters are exported along with their values on all nodes.
Counters can be exported using a script. Default behavior: When an ETL script is not provided, Counters are exported.
Counters and the Data Subscriptions task
Data Subscriptions can be initiated by document changes, including those caused by Counter Name updates.
Documents will not be delivered in reaction to Counter Value modification.
Counters and Other Features: Summary
Use this table to find if and how various RavenDB features are triggered by Counters,
and how the various features handle Counter values.
In the Triggered By column:
Document Change - Feature is triggered by a Counter Name update.
Countrer Value Modification - Feature is triggered by a Counter Value modification.
Time Schedule - Feature is invoked by a pre-set time routine.
No Trigger - Feature is executed manually, through the Studio or by a Client.
In the Counter Value column:
Accumulated - Counter Value is handled as a single accumulated sum.
Distributed - Counter Value is handled as a series of values maintained by cluster nodes.
You can include Counters while loading a document.
An included Counter is retrieved in the same request as its owner-document and is held by the session,
so it can be immediately retrieved when needed with no additional remote calls.