Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tutosrive/fastapi-CRUD-MongoDB/llms.txt

Use this file to discover all available pages before exploring further.

The DELETE /tasks/{id} endpoint permanently removes a task document from the MongoDB task collection. The controller uses find_one_and_delete({'_id': ObjectId(id)}) which atomically finds and deletes the document in a single operation. On success it returns a FastAPI Response with HTTP status 204 No Content and an empty body. If no document matches the given id, the server raises an HTTPException with status 404 and the detail "Task Not Found!". This operation is irreversible — there is no soft-delete or recovery mechanism. DELETE /tasks/{id}

Path Parameters

id
string
required
MongoDB ObjectId expressed as a 24-character hex string (e.g. 64a1b2c3d4e5f6789abcde01) identifying the task to delete.

Example Request

curl -X DELETE http://localhost:5000/tasks/64a1b2c3d4e5f6789abcde01

Example Response

HTTP/1.1 204 No Content
The response body is intentionally empty on success. A 204 No Content status code confirms the task was found and deleted. Do not expect a JSON payload in the response.

Error Responses

StatusDetailCause
404 Not Found"Task Not Found!"No task document exists in MongoDB with the provided id, or it was already deleted.
500 Internal Server ErrorServer error messageDatabase connection failure or malformed ObjectId string.
Deletion is permanent. Once a task document has been removed from MongoDB there is no built-in way to recover it. Ensure your client confirms the correct id before issuing this request.
Passing an invalid ObjectId string (not a 24-character hex string) will cause bson.errors.InvalidId to be raised by the ObjectId() constructor, resulting in a 500 error rather than 404. Always supply a well-formed id obtained from a previous create or list response.

Build docs developers (and LLMs) love