---
title: "Get Counters Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/counters/get-counters"
version: "6.2"
language: "nodejs"
---

# Get Counters Operation

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/counters/get-counters.md), [Java](https://docs.ravendb.net/6.2/client-api/operations/counters/get-counters.java.md), [PHP](https://docs.ravendb.net/6.2/client-api/operations/counters/get-counters.php.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

This operation is used to get counters' values for a specific document.  
It can be used to get the value of a single counter, multiple counters' values, or all counters' values.

## Syntax

```javascript
// Get single counter
const getCountersOp = new GetCountersOperation(docId, counter);
const getCountersOp = new GetCountersOperation(docId, counter, returnFullResults = false);
```

```javascript
// Get multiple counters
const getCountersOp = new GetCountersOperation(docId, counters);
const getCountersOp = new GetCountersOperation(docId, counters, returnFullResults = false);
```

```javascript
// Get all counters of a document
const getCountersOp = new GetCountersOperation(docId);
```

| Parameter | Type | Description |
| - | - | - |
| **docId** | string | The ID of the document that holds the counters |
| **counter** | string | The name of the counter to get |
| **counters** | string\[] | The list of counter names to get |
| **returnFullResults** | boolean | A flag which indicates if the operation should include a dictionary of counter values per database node in the result |

> **Info**
>
> **The full results flag:**
>
> If RavenDB is running in a distributed cluster, and the database resides on several nodes,  
> then a counter can have a different *local* value on each database node.  
> The total counter value is the sum of all the local values of this counter from each node.  
> To get the counter values per database node, set the `returnFullResults` flag to `true`.

## Return Value

The operation returns a `CountersDetail` object, which holds a list of `CounterDetail` objects

```javascript
// The CounterDetails object:
// ==========================
{
  // A list of "CounterDetail" objects;
  counters;
}
```

```javascript
// The CounterDetail object:
// =========================
{
  // ID of the document that holds the counter;
  documentId; // string
  
  // The counter name
  counterName; //string

  // Total counter value
  totalValue; // number
  
  // A dictionary of counter values per database node
  counterValues?; 
  
  // Etag of counter
  etag?; // number;

  // Change vector of counter
  changeVector?; // string
}
```

## Examples

Assume we have a `users/1` document that holds 3 counters:  
`Likes`, `Dislikes` and `Downloads` -  with values 10, 20 and 30 (respectively)

### Example #1 : Get single counter

```javascript
// Define the get counters operation
const getCountersOp = new GetCountersOperation("users/1", "Likes");

// Execute the operation by passing it to operations.send
const result = await documentStore.operations.send(getCountersOp);
const counters = result.counters;
```

#### Result:

```json
{
  "counters": 
  [
  	{
  		"documentId"    : "users/1",
  		"counterName"   : "Likes",
  		"totalValue"    : 10,
  		"counterValues" : null
  	}
  ]
}
```

### Example #2 : Get multiple counters

```javascript
const getCountersOp = new GetCountersOperation("users/1", ["Likes", "Dislikes"]);

const result = await documentStore.operations.send(getCountersOp);
const counters = result.counters;
```

#### Result:

```json
{
  "counters": 
  [
  	{
  		"documentId"    : "users/1",
  		"counterName"   : "Likes",
  		"totalValue"    : 10,
  		"counterValues" : null
  	},
      {
  		"documentId"    : "users/1",
  		"counterName"   : "Dislikes",
  		"totalValue"    : 20,
  		"counterValues" : null
  	}
  ]
}
```

### Example #3 : Get all counters

```javascript
const getCountersOp = new GetCountersOperation("users/1");

const result = await documentStore.operations.send(getCountersOp);
const counters = result.counters;
```

#### Result:

```json
{
  "counters": 
  [
  	{
  		"documentId"    : "users/1",
  		"counterName"   : "Likes",
  		"totalValue"    : 10,
  		"counterValues" : null
  	},
      {
  		"documentId"    : "users/1",
  		"counterName"   : "Dislikes",
  		"totalValue"    : 20,
  		"counterValues" : null
  	},
      {
  		"documentId"    : "users/1",
  		"counterName"   : "Downloads",
  		"totalValue"    : 30,
  		"counterValues" : null
  	}
  ]
}
```

### Example #4 : Include full values in the result

```javascript
const getCountersOp = new GetCountersOperation("users/1", "Likes", true);

const result = await documentStore.operations.send(getCountersOp);
const counters = result.counters;
```

#### Result:

Assuming a 3-node cluster, the distribution of the counter's value to nodes A, B, and C could be as follows:

```json
{
  "counters": 
  [
  	{
  		"documentId"    : "users/1",
  		"counterName"   : "Likes",
  		"totalValue"    : 10,
  		"counterValues" : 
          {
              "A:35-UuCp420vs0u+URADcGVURA" : 5,
              "B:83-SeCFU29daUOxfjUcAlLiJw" : 3,
              "C:27-7i7GP8bOOkGYLNflO/rSeg" : 2,
          }
  	}
  ]
}
```

## See also

- [What are Operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.nodejs.md)
- [Counter Batch Operation](https://docs.ravendb.net/6.2/client-api/operations/counters/counter-batch.nodejs.md)
