Skip to content

truncate all docs in collection#2127

Merged
kishorenc merged 4 commits into
typesense:v28from
krunal1313:collection_truncate_all
Jan 7, 2025
Merged

truncate all docs in collection#2127
kishorenc merged 4 commits into
typesense:v28from
krunal1313:collection_truncate_all

Conversation

@krunal1313

@krunal1313 krunal1313 commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

Change Summary

  • add end-point /collections/:collection/documents?truncate=true to remove all docs from collection
  • add test

Truncate all docs from collection

To truncate all docs from a collection, one need to put a DELETE request to end-point /collections/:collection/documents?truncate=true like below,

curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -X DELETE  "http://localhost:8108/collections/hnstories/documents?truncate=true"

Here, hnstories is the collection to truncate all docs.

And we get the response like below,

{"num_deleted":1000000}

Here num_deleted is the count of docs deleted.

In case of empty collection we get response accordingly,

{"num_deleted":0}

PR Checklist

Comment thread src/main/typesense_server.cpp Outdated
Comment thread src/core_api.cpp Outdated
Comment thread src/collection.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants