3 ms·
I'm surprised this doesn't use ODMantic. It, like FastAPI, is based on Pydantic, so they can be integrated seamlessly together: https://art049.github.io/odmanti
by nerdponx 5y ago
I'm surprised this doesn't use ODMantic. It, like FastAPI, is based on Pydantic, so they can be integrated seamlessly together: https://art049.github.io/odmantic/usage_fastapi/ https://art049.github.io/odmantic/usage_fastapi/
I know some people don't like the idea of putting schemas and migrations in a MongoDB-based system, but having statically-type-hinted automatic schema validation really improves productivity and largely eliminates huge categories of bugs.
I think most systems that use MongoDB should probably be using a traditional RDBMS instead[1], but I see these kinds of tools as a form of "harm reduction". People are going to use MongoDB no matter what, so you might as well at least give them the tools to build applications more safely, with less wheel-reinvention and boilerplate than would otherwise be required.
Unless you are storing truly arbitrary unstructured "documents" with no associated metadata whatsoever (like some kind of JSON rich text format), or if you know that the schema will definitely change over time and you are willing to write very very very defensive code to accommodate this situation, then there's no reason not to use a schema validation layer like ODMantic in my opinion. And those kinds of data systems don't even make sense to use with FastAPI anyway, which is designed specifically for the use case of a fixed set of REST-like endpoints and strict input validation according to a fixed schema.
[1]: The exception is that if you are really really sure you won't need to do a lot of join/$lookup operations, you can aggressively denormalize your data, and/or you want the easy MongoDB scalability (and aren't bothered by its caveats).
- walking_dev 5y agoI agree with the part of RDBMS. As for your suggestion about ODMantic, I was actually planning to use an ORM at the begging, but I couldn't find a stable one with asynchronous features. So, I decided to use motor for now. ODMantic may be worth studying.