MongoObjectId
The MongoObjectId is a subclass of the bson
ObjectId class. It is used to define the id field of your MongoModel. It is also used to generate the OpenAPI schema for your routes.
The only goal behing it, is to make it work like it should be used by MongoDb .
Use MongoObjectId as type hint for your id field
...
class MyModel(MongoModel):
id: Annotated[ObjectId, MongoObjectId] | None = None
You can also use it as a foreign field for your embed or lookup models.
Use MongoObjectId as type hint for your foreign fields
...
class MyModel(MongoModel):
id: Annotated[ObjectId, MongoObjectId] | None = None
user_id: Annotated[ObjectId, MongoObjectId]