Open alecandido opened 1 year ago
The command
approach requires more effort from the developer point of view in my opinion. Pydantic+MongoDB seems the standard (even mentioned in mongo's docs) when using APIs like FastAPI, so I would go for this option.
Ok, perfect, I will go that way.
For the sake of reporting:
mongoengine
. It is another reliable package, implementing an ODM (essentially SQLAlchemy for Mongo). However, the object side seems less featureful than Pydantic
@scarrazza @stavros11 I'm now facing the problem of whom delegating the validation to.
I have essentially two ingredients, that generate two possible options:
command
passing a JSON schemaThe database has of course has to be there, but it only works with dictionaries (and at most
TypedDict
for type hints). However, Pydantic gives me the objects, it should be able to turn the model specified by them into a JSON schema (which I would not need any longer), and it has a better integration with type checks.On the one side, I wonder if I should keep insisting with Pydantic adoption, since I could do everything with MongoDB (giving up on type hints, and writing manually the JSON schema). On the other, I really want the objects, rather than dictionaries around, and Pydantic is a dependency actively developed, with >13k stars on GitHub... all in all it seems quite reliable.
So, the two tools are so complete that they span part of the things done by the other, and in particular validation is in both. But they are also complementary, so I would just decide to whom attributing the intersection, and keep using both to have the full set of features.