Replies: 1 comment
-
Just ditch mongoose and use the mongodb driver directly. The document model can be modelled with typebox as well. You can enforce it directly on the database level by adding a json schema to your mongodb collections. This will enforce your document model not just on the application level (like with mongoose) but on the database level. Moreover, you get rid of the redundant mongoose schema. See: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! I'm using ElysiaJS and I find myself writing two versions of my schemas, a Mongoose one for using as a document model, and the TypeBox ones for using as guards and return types. Usually though, they're exactly the same, or at least extremely similar (thus extendable one from the other). Is there a known way of just writing one of these schemas and inferring the other? Ideally, I would just write a Mongoose schema, for example, and it should work as a return type as well (although maybe after a conversion process, perhaps). Or the other way around, the key is eliminating complexity
Beta Was this translation helpful? Give feedback.
All reactions