---
title: "Delete"
description: "Guide to deleting records in Aerospike using the Node.js client, covering default and durable delete methods."
---

# Delete

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

## Description

Demonstrates single record deleletions in an Aerospike database.

## Setup

### Boilerplate

The examples below leverage the following boilerplate to initialize the Aerospike module and connect to a server before deleting a record.

```js
const Aerospike = await import("aerospike");

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

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

// Creates a key with the namespace "sandbox", set "ufodata", and user key 5001

const key = new Aerospike.Key("sandbox", "ufodata", 5001);

// Establishes a connection to the server

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

## Policies

Just as Create and Update, Delete utilizes write [policies](https://aerospike.com/docs/database/learn/policies) that can be defined per command.

The following example creates a write policy that enables durable deletes.

```js
// Can use a previously defined write policy or create a new one

const deletePolicy = new Aerospike.WritePolicy({

  durableDelete: true,

});
```

::: note
Record deletion can also be controlled through expiration, a write policy that defines the time-to-live (ttl), or number of seconds a record will live before being removed by the server. The default ttl is to live forever.

Refer to [Data Retention](https://aerospike.com/docs/database/manage/namespace/retention) for more information.
:::

## Delete a record

### Default policy

Aerospike deletes a record efficiently by only dropping the primary index entry. The record space on device is recovered during garbage collection.

The following example shows how to delete a record using the default write policy.

::: caution
Using the default write policy could result in having previously persisted versions of deleted objects resurrected upon a cold restart of the namespace. See [Durable Deletes](#durable-deletes) below for more information on preventing zombie records.
:::

```js
// Delete record with default write policy

await client.remove(key);
```

::: note
Updating a bin value to `null`, when it is the only bin in the record, deletes the record. See [Delete a Bin](https://aerospike.com/docs/develop/client/node/usage/atomic/update#delete-a-bin) for information on setting a bin value to `null`.
:::

### Durable deletes

When a command results in deletion of a record and the `durable delete` write policy is set to `true`, a tombstone record is written to disk to prevent previous versions of the record from returning during a cold restart. Refer to [Durable Deletes](https://aerospike.com/docs/database/learn/architecture/durable-deletes) for more information.

The following example uses the write policy set above to durably delete a record.

```js
// Durably delete a record with the write policy

await client.remove(key, deletePolicy);
```

## Code block

Expand this section for a single code block to durably delete a record

```js
const Aerospike = await import("aerospike");

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

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

// Establishes a connection to the server

const client = await Aerospike.connect(config);

// Creates a key with the namespace "sandbox", set "ufodata", and user key 5001

const key = new Aerospike.Key("sandbox", "ufodata", 5001);

// Can use a previously defined write policy or create a new one

const deletePolicy = new Aerospike.WritePolicy({

  durableDelete: true,

});

// Durably delete a record with the write policy

await client.remove(key, deletePolicy);

// Close the connection to the server

await client.close();
```