diff --git a/README.md b/README.md index 7deeba1..3106b3e 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ pip install pydantic-mongo ```python from bson import ObjectId from pydantic import BaseModel -from pydantic_mongo import AbstractRepository, ObjectIdField +from pydantic_mongo import AbstractRepository, PydanticObjectId from pymongo import MongoClient -from typing import List +from typing import Optional, List import os class Foo(BaseModel): @@ -31,7 +31,7 @@ class Bar(BaseModel): banana: str = 'y' class Spam(BaseModel): - id: ObjectIdField = None + id: Optional[PydanticObjectId] = None foo: Foo bars: List[Bar] @@ -64,7 +64,7 @@ spam_repository.delete(spam) # Find One By Id result = spam_repository.find_one_by_id(spam.id) -# Find One By Id using string if the id attribute is a ObjectIdField +# Find One By Id using string if the id attribute is a PydanticObjectId result = spam_repository.find_one_by_id(ObjectId('611827f2878b88b49ebb69fc')) assert result.foo.count == 2 diff --git a/test/test_repository.py b/test/test_repository.py index a76030e..81d51bc 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -1,4 +1,4 @@ -from typing import Annotated, List, Optional, cast +from typing import List, Optional, cast import mongomock import pytest