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

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

<CodeGroup>
  ```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.
  </Note>

  ```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}
  curl -i -X POST \
    --url "$BASE_URL/projects/$PROJECT_NAME/collections/{collectionName}/docs/delete" \
    --header 'content-type: application/json' \
    --header 'x-api-key: <YOUR_API_KEY>' \
    --data '{
    "ids": [
      "example-doc-id-1",
      "example-doc-id-2"
    ]
  }'
  ```
</CodeGroup>

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

<CodeGroup>
  ```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 := &lambdadb.QueryFilter{QueryString: &lambdadb.QueryStringFilter{Query: "genre:documentary AND year:2019"}}
  _, err := client.Collection("your_collection_name").Docs().Delete(ctx, lambdadb.DeleteDocsInput{Filter: filter})
  ```

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

## Delete an entire collection

To remove all documents from a collection,
[delete the collection](/guides/collections/manage-collections#delete-a-collection) and
[recreate it](/guides/collections/create-a-collection#create-a-collection-from-scratch).
Deletion is asynchronous: if you reuse the **same** collection name, wait until the name is fully released (for example by polling describe until the collection returns not found) before calling create—see [Wait for deletion before recreating](/guides/collections/manage-collections#wait-for-deletion-before-recreating).
