From c1abbd29f23b221c5840a5ce5b0b6a70c7da3722 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh <148898879+rachel-mack@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:35:04 -0400 Subject: [PATCH 1/2] update pymongo version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2507499..56e7967 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,7 @@ pydantic==2.6.3 # fastapi pydantic-core==2.16.3 # via pydantic -pymongo==4.5.0 +pymongo==4.13.1 # via motor sniffio==1.3.0 # via anyio From f2a5b1d4db2b56d24191fd28f52357fd58c815ca Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh <148898879+rachel-mack@users.noreply.github.com> Date: Fri, 20 Jun 2025 16:27:46 -0400 Subject: [PATCH 2/2] make create_student more efficient --- app.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 67fbfa2..17c1d1a 100644 --- a/app.py +++ b/app.py @@ -100,13 +100,11 @@ async def create_student(student: StudentModel = Body(...)): A unique `id` will be created and provided in the response. """ - new_student = await student_collection.insert_one( - student.model_dump(by_alias=True, exclude=["id"]) - ) - created_student = await student_collection.find_one( - {"_id": new_student.inserted_id} - ) - return created_student + new_student = student.model_dump(by_alias=True, exclude=["id"]) + result = await student_collection.insert_one(new_student) + new_student["_id"] = result.inserted_id + + return new_student @app.get(