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 GET /tasks/{id} endpoint looks up a single task document in MongoDB using the provided ObjectId string. The controller calls find_one({'_id': ObjectId(id)}), converts the raw BSON document to a clean Python dict via task_entity(), and returns it as a JSON response. If no document matches the given id, the server raises an HTTPException with status 404 and the detail message "Task Not Found!". GET /tasks/{id}

Path Parameters

id
string
required
MongoDB ObjectId expressed as a 24-character hex string (e.g. 64a1b2c3d4e5f6789abcde01). This value is the id field returned when a task is created.

Response Fields

id
string
MongoDB ObjectId serialised as a 24-character hex string.
title
string
The short title of the task.
description
string
A detailed description of what the task involves.
completed
boolean
Whether the task has been completed. Defaults to false.
created_by
string
Identifier for the user who created the task.

Example Request

curl http://localhost:5000/tasks/64a1b2c3d4e5f6789abcde01

Example Response

{
  "id": "64a1b2c3d4e5f6789abcde01",
  "title": "Buy groceries",
  "description": "Milk, eggs, bread",
  "completed": false,
  "created_by": "alice@example.com"
}

Error Responses

StatusDetailCause
404 Not Found"Task Not Found!"No task document exists in MongoDB with the provided id.
500 Internal Server ErrorServer error messageDatabase connection failure or malformed ObjectId string.
Passing a string that is not a valid 24-character hex ObjectId (e.g. "abc") will cause bson.errors.InvalidId to be raised by the ObjectId() constructor, resulting in a 500 error. Always supply a well-formed ObjectId obtained from a previous create or list response.

Build docs developers (and LLMs) love