I hope somebody could explain me what I am doing wrong here.
I have a fast api app connected to a mongoldb, I uploaded some fake data to play a bit with the framework and learn.
I have some documents in mongoldb structure like this
{
_id: ObjectId('63121f6c7e4b47e418bc3128'),
Name: 'Test',
Surname: 'Example',
Email: "[email protected]"
}
I am trying to code a route to query a document based on the email, as follow:
@app.get("/app/{email}")
async def find_email(email):
return datasEntity(data_db.data.find({"email": email}))
when I run my api, I get back a 200 code but the response body is an empty string.
Can please anyone help to understand what I am doing wrong here? How can I find a document based on the email provided?
Thank you so much for any help you can provide
CodePudding user response:
I found my issue. It was a typo in my Schema and I was querying the wrong key.
CodePudding user response:
use find_one:
(data_db.data.find_one({"email": email}))