> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lambdadb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete data

> Remove documents from a LambdaDB collection by specifying document IDs. Includes Python, TypeScript, Go, and cURL deletion code examples.

This page shows you how to use the delete endpoint to remove documents from a collection.

The examples delete from the default branch, `main`. To delete from another existing writable branch, include its name in the REST request's optional `branch` field. A tag or alias is not a valid write target. See [Branch selection](https://docs.lambdadb.ai/guides/data-versioning/branches-tags-aliases.md#write-to-a-branch).

Specify exactly one of `ids` or `filter`. An empty request, both fields together, or `partitionFilter` alone returns `400 BadRequest`. For partitioned collections, `partitionFilter` narrows the IDs or filter selection; it is not an independent deletion selector.

## Delete documents by IDs

Since LambdaDB documents can always be efficiently accessed using their ID,
deleting by ID is the most efficient way to remove specific records.

```python Python theme={null}
from lambdadb import LambdaDB

with LambdaDB(
    project_api_key="YOUR_API_KEY",
    base_url="YOUR_BASE_URL",
    project_name="YOUR_PROJECT_NAME",
) as client:
    coll = client.collection("your_collection_name")
    coll.docs.delete(ids=["example-doc-id-1", "example-doc-id-2"])
```

> [!NOTE]
>
> Python: `LambdaDB` supports context manager usage. `__enter__` returns the client, and `__exit__` calls `client.close()` (closing the SDK-owned HTTP client) and makes the client unusable after the `with` block. If you don't use `with`, call `client.close()` when you're done. If you pass a custom `client=`/`async_client=`, you own closing it.

```typescript TypeScript theme={null}
import { LambdaDBClient } from "@functional-systems/lambdadb";

const client = new LambdaDBClient({
  projectApiKey: "YOUR_API_KEY",
  baseUrl: "YOUR_BASE_URL",
  projectName: "YOUR_PROJECT_NAME",
});
await client.collection("your_collection_name").docs.delete({
  ids: ["example-doc-id-1", "example-doc-id-2"],
});
```

```go Go theme={null}
package main

import (
  "context"
  "log"
  lambdadb "github.com/lambdadb/go-lambdadb"
)

func main() {
  ctx := context.Background()
  client := lambdadb.New(
    lambdadb.WithBaseURL("YOUR_BASE_URL"),
    lambdadb.WithProjectName("YOUR_PROJECT_NAME"),
    lambdadb.WithAPIKey("YOUR_API_KEY"),
  )
  _, err := client.Collection("your_collection_name").Docs().Delete(ctx, lambdadb.DeleteDocsInput{
    Ids: []string{"example-doc-id-1", "example-doc-id-2"},
  })
  if err != nil {
    log.Fatal(err)
  }
}
```

```bash cURL theme={null}
BASE_URL="YOUR_BASE_URL"
PROJECT_NAME="YOUR_PROJECT_NAME"
COLLECTION_NAME="your_collection_name"
LAMBDADB_PROJECT_API_KEY="YOUR_API_KEY"

curl -i -X POST \
  --url "$BASE_URL/projects/$PROJECT_NAME/collections/$COLLECTION_NAME/docs/delete" \
  --header 'content-type: application/json' \
  --header "x-api-key: $LAMBDADB_PROJECT_API_KEY" \
  --data '{
  "ids": [
    "example-doc-id-1",
    "example-doc-id-2"
  ]
}'
```

## Delete documents by query

To delete documents based on their data, pass a `filter` query to the delete operation.
This deletes all documents matching the filter query.

For example, to delete all documents with genre "documentary" and year 2019 from a collection, use the following code:

These snippets reuse the imports, client setup, and cURL variables above. For Go, replace the ID-deletion call inside `main` with the filter example below.

```python Python theme={null}
with LambdaDB(
    project_api_key="YOUR_API_KEY",
    base_url="YOUR_BASE_URL",
    project_name="YOUR_PROJECT_NAME",
) as client:
    coll = client.collection("your_collection_name")
    coll.docs.delete(query_filter={"queryString": {"query": "genre:documentary AND year:2019"}})
```

```typescript TypeScript theme={null}
await client.collection("your_collection_name").docs.delete({
  filter: { queryString: { query: "genre:documentary AND year:2019" } },
});
```

```go Go theme={null}
filter := map[string]any{
  "queryString": map[string]any{"query": "genre:documentary AND year:2019"},
}
_, err := client.Collection("your_collection_name").Docs().Delete(ctx, lambdadb.DeleteDocsInput{Filter: filter})
if err != nil {
  log.Fatal(err)
}
```

```bash cURL theme={null}
curl -i -X POST \
  --url "$BASE_URL/projects/$PROJECT_NAME/collections/$COLLECTION_NAME/docs/delete" \
  --header 'content-type: application/json' \
  --header "x-api-key: $LAMBDADB_PROJECT_API_KEY" \
  --data '{
  "filter": {
    "queryString": {
      "query": "genre:documentary AND year:2019"
    }
  }
}'
```

## Delete an entire collection

To remove all documents from a collection,
[delete the collection](https://docs.lambdadb.ai/guides/collections/manage-collections.md#delete-a-collection) and
[recreate it](https://docs.lambdadb.ai/guides/collections/create-a-collection.md#create-a-collection-from-scratch).
The delete operation makes the logical collection unavailable before returning `200 OK`, so the same collection name can be reused immediately.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.