How to parse and read “_id” field from and to a pydantic model?

Viewed 736

class User(BaseModel):

name : str
id : PydanticObjectId  = Field(None, alias='_id')

data = self.coll.find_one({"email": email})

        user = User(**data)
        return user 

now when my data is returned from mongo db it is in the form of doc dictionary. when I verify the elements of the user I can't find any field named as id. Why this is so? If I replace the id from _id then also the same issue remains.

0 Answers
Related