---
title: "Session: How to Get and Modify Entity Metadata"
url: "https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata"
version: "6.2"
language: "nodejs"
---

# Session: How to Get and Modify Entity Metadata

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata.md), [Java](https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata.java.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."

When a document is downloaded from the server, it contains various metadata information like ID or current change-vector. This information is stored in a session and is available for each entity using the `getMetadataFor` method from the `advanced` session operations.

## Get the Metadata

```javascript
session.advanced.getMetadataFor(entity);
```

| Parameters | | |
| - | - | - |
| **entity** | object | Entity for which metadata will be returned. |

| Return Value | |
| - | - |
| object | Returns the metadata for the specified entity. Throws an exception if the `instance` is not tracked by the session. |

### Example

```javascript
const employee = await session.load("employees/1-A");
const metadata = session.advanced.getMetadataFor(employee);
```

## Modify the Metadata

After getting the metadata from `session.advanced.getMetadataFor()` you can modify it.

> **Note**
>
> Keys in the metadata that starting with *@* are reserved for RavenDB use

### Example I

```javascript
const user = new User();
user.name = "Idan";

await session.store(user);

const metadata = session.advanced.getMetadataFor(user);
metadata["Permissions"] = "READ_ONLY";
await session.saveChanges();
```

### Example II

```javascript
const user = await session.load("users/1-A");
const metadata = session.advanced.getMetadataFor(user);
metadata["Permissions"] = "READ_AND_WRITE";
await session.saveChanges();
```

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.nodejs.md)
- [How to Get Entity Change-Vector](https://docs.ravendb.net/6.2/client-api/session/how-to/get-entity-change-vector.nodejs.md)
- [How to Get Entity Last Modified](https://docs.ravendb.net/6.2/client-api/session/how-to/get-entity-last-modified.nodejs.md)
- [Indexing Metadata](https://docs.ravendb.net/6.2/indexes/indexing-metadata.nodejs.md)
