jedireza / mongo-models

:package: Map JavaScript classes to MongoDB collections
MIT License
67 stars 28 forks source link

Would you consider an alternative? #61

Open ddfridley opened 9 months ago

ddfridley commented 9 months ago

I've been using mongo-models for a long time but I know it's been hard to keep up with all the changes to Mongodb. I've seen some of the updates to the README about not supporting it any more. But it's been a pattern that I appreciate and so I created this:

@enciv/mongo-collections

It's not exactly compatible with mongo-models but migration would be strait forward. And people could continue using the schemas and validation pattern of mongo-models, or they could migrate to the schemas of mongodb.

The main implementation difference is that in mongo-collections the Collection class actively copies all the properties of the Mongodb Collection instance, after the connection to the server is made - so it 'inherits' all the methods of a collection.

I would appreciate any feedback/questions/suggestions on it.

jedireza commented 9 months ago

Thanks for sharing. I have a solution very similar to Mongo Models that I use in TypeScript, though it still uses Joi for runtime validation. Because of that I still have to maintain the model property types and Joi schemas. It's not too bad, but could be better. Also there are some quirks with class inheritance and constructors that isn't very elegant.

If someone were to consider upgrading this repo to support TypeScript, it would be a good idea to look further into Zod (which I haven't done).