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

# Get Counters Operation

> Client language: C#. Also available for [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), [Node.js](https://docs.ravendb.net/6.2/client-api/operations/counters/get-counters.nodejs.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

#### Get Single Counter

```csharp
public GetCountersOperation(string docId, string counter, bool returnFullResults = false)
```

| Parameters | | |
| - | - | - |
| **docId** | string | The ID of the document that holds the counters |
| **counter** | string | The name of the counter to get |
| **returnFullResults** | bool | A flag which indicates if the operation should include a dictionary of counter values per database node in the result |

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

#### Get Multiple Counters

```csharp
public GetCountersOperation(string docId, string[] counters, bool returnFullResults = false)
```

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

#### Get All Counters of a Document

```csharp
public GetCountersOperation(string docId, bool returnFullResults = false)
```

| Parameters | | |
| - | - | - |
| **docId** | string | The ID of the document that holds the counters |
| **returnFullResults** | bool | A flag which indicates if the operation should include a dictionary of counter values per database node in the result |

## Return Value

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

```csharp
public class CountersDetail
{
  public List<CounterDetail> Counters;
}
```

```csharp
public class CounterDetail
{
  public string DocumentId; // ID of the document that holds the counter
  public string CounterName; // The counter name
  public long TotalValue; // Total counter value
  public Dictionary<string, long> CounterValues; // A dictionary of counter values per database node
  public long Etag; // Counter Etag
  public string ChangeVector; // Change vector of the counter
}
```

## 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

```csharp
var operationResult = store.Operations
  .Send(new GetCountersOperation("users/1", "likes"));
```

#### Result:

```json
{
  "Counters": 
  [
  	{
  		"DocumentId" : "users/1",
  		"CounterName" : "likes",
  		"TotalValue" : 10,
  		"CounterValues" : null
  	}
  ]
}
```

### Example #2 : Get multiple counters

```csharp
var operationResult = store.Operations
  .Send(new GetCountersOperation("users/1", new []{"likes", "dislikes" }));
```

#### 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

```csharp
var operationResult = store.Operations
  .Send(new GetCountersOperation("users/1"));
```

#### 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

```csharp
var operationResult = store.Operations
  .Send(new GetCountersOperation("users/1", "likes", true));
```

#### 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.md)
- [Counter Batch Operation](https://docs.ravendb.net/6.2/client-api/operations/counters/counter-batch.md)
