INNER CODE UNIT · Python

delete_student

mongodb-developer/mongodb-with-fastapi · app.py:180

async def delete_student(id: str):
    """
    Remove a single student record from the database.
    """
    delete_result = await student_collection.delete_one({"_id": ObjectId(id)})

    if delete_result.deleted_count == 1:
        return Response(status_code=status.HTTP_204_NO_CONTENT)

    raise HTTPException(status_code=404, detail=f"Student {id} not found")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…