Delete documents (HTTP)
|
For details about additional languages, see: |
Finds documents in a collection using filter clauses, and then deletes those documents.
|
If you don’t use a filter, or if you use an empty filter, then this method deletes all documents in the collection. |
This method does not support sort parameters, including vector search.
If you want to use sort parameters to find documents, use the method to find documents instead.
Then, use the method to delete a single document to delete each found document by ID.
|
Ready to write code? See the examples for this method to get started. |
Result
Deletes documents that match the specified parameters and returns an object that includes details about the number of documents that were deleted.
A result that includes a deleted count of -1 indicates that every document in the collection was deleted.
Example response:
{
"status": {
"deletedCount": 1
}
}
If more than 20 documents match the specified filter parameters, only the first 20 documents are deleted.
In this case, the status.deletedCount is 20, and the status.moreData value is true.
To delete the next batch of 20 documents, you must resend the request.
Example response if more documents match the filter than were deleted:
{
"status": {
"deletedCount":20,
"moreData":true
}
}
Signature
Use the deleteMany command.
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/COLLECTION_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteMany": {
"filter": FILTER
}
}'
Parameters
| Name | Type | Summary | ||
|---|---|---|---|---|
|
|
An object that defines filter criteria using the Data API filter syntax. The method only finds documents that match the filter criteria. Filters can improve performance by reducing the number of documents that the Data API processes. You must use For a list of available filter operators and more examples, see Filter operators for collections (HTTP). Filters can use only indexed fields. If you apply selective indexing when you create a collection, you cannot reference non-indexed fields in a filter. For an example, see Delete documents that match a filter.
|
Examples
The following examples demonstrate how to delete documents in a collection.
Delete documents that match a filter
You can use a filter to find documents that match specific criteria.
For example, you can find documents with an is_checked_out value of false and a number_of_pages value less than 300.
For a list of available filter operators and more examples, see Filter operators for collections (HTTP).
Filters can use only indexed fields. If you apply selective indexing when you create a collection, you cannot reference non-indexed fields in a filter.
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME/COLLECTION_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteMany": {
"filter": {"$and": [
{"is_checked_out": false},
{"number_of_pages": {"$lt": 300}}
]}
}
}'
Delete all documents
To delete all documents, use an empty filter.
A result that includes a deleted count of -1 indicates that every document in the collection was deleted.
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME/COLLECTION_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteMany": {
"filter": {}
}
}'
Delete more than 20 documents
You can only delete 20 documents per HTTP request.
If more than 20 documents match the specified filter parameters, only the first 20 documents will be deleted.
In this case, the status.deletedCount is 20, and the status.moreData value is true.
To delete the next batch of 20 documents, you must resend the request.
To delete all documents, continue sending the request until the status.moreData value is omitted from the response.
If you use an empty filter, you do not need to batch your requests. In that case, the server automatically iterates over batches of documents until all documents are deleted.