---
title: "Update"
description: "Learn how to update JSON documents and Collection Data Types like lists and maps with the Aerospike Node.js client."
---

# Update

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

Jump to the [Code block](#code-block) for a combined complete example.

## Create a document record

The following example demonstrates reading a document record with a JSON helper library. In Aerospike, JSON documents are handled as a [Collection Data Type (CDT)](https://aerospike.com/docs/develop/data-types/collections). A JSON object is equivalent to a [map](https://aerospike.com/docs/develop/data-types/collections/map), and a JSON array is equivalent to a [list](https://aerospike.com/docs/develop/data-types/collections/list).

In this example, we create the following JSON document:

```json
employees = [{"id": "09", "name": "Nitin", "department": "Finance"},

             {"id": "10", "name": "Jonathan", "department": "Human Resources"},

             {"id": "11", "name": "Caitlin", "department": "Engineering"}]
```

The JSON document is added to a bin called `employees` which is of data type [list](https://aerospike.com/docs/develop/data-types/collections/list). There are some advantages to holding an entire document in a single bin, rather than spreading out the document’s fields over multiple bins. There is less metadata overhead when namespaces contain fewer, larger bins.

### Setup

Import the necessary helpers, create a client connection, and create a key.

```js
import { readFile } from "node:fs/promises";

const Aerospike = await import("aerospike");

const maps = Aerospike.maps;

// Set hosts to your server's address and port

const config = { hosts: "YOUR_HOST_ADDRESS:YOUR_PORT" };

// Create a key

const key = new Aerospike.Key("test", "demo", 5001);

// Establishes a connection to the server

const client = await Aerospike.connect(config);
```

### Update

Update the newly created document.

```js
// Update 'department' field from 'Engineering' to 'Support' in 3rd employee record

const ops = [

  maps

    .putItems("employees", { department: "Support" })

    .withContext((ctx) => ctx.addListIndex(2)),

];
```

## Code block

Expand this section for a single code block to update a document record.

```js
import { readFile } from "node:fs/promises";

const Aerospike = await import("aerospike");

const maps = Aerospike.maps;

// Set hosts to your server's address and port

const config = { hosts: "YOUR_HOST_ADDRESS:YOUR_PORT" };

// Create a key

const key = new Aerospike.Key("test", "demo", 5001);

// Establishes a connection to the server

const client = await Aerospike.connect(config);

// Update 'department' field from 'Engineering' to 'Support' in 3rd employee record

const ops = [

  maps

    .putItems("employees", { department: "Support" })

    .withContext((ctx) => ctx.addListIndex(2)),

];

const result = await client.operate(key, ops);

console.info("Name of 3rd employee: ", result.bins.employees);

await client.close();
```