Closed chill-cod3r closed 3 years ago
Sorry for a late response, @wolfejw86
Definitely this is must have feature. As a quick fix based on current methods, it's possible to use apiValues method on the model. You can check out https://github.com/jeka-kiselyov/sample-fastify-mongoose-api-app/blob/master/models/user.js ( filtering out password in API responses ) to check it in action. But projection would be much faster, I will add it to methods.
Is this something you are still interested in implementing? If so, I can submit a pull request.
This looks great! @phmz , thank you! I will check tests and do a merge tomorrow.
Works great and nicely covered. Merged and published to npm as 1.1.7
Thanks again @phmz
It would be awesome if projections could be defined for certain routes (such as the list route) or if they could be sent in via route query params. Do you have any thoughts on the best way to go about this / any interest in adding it as a feature? I'd be happy to contribute.
Why would it be useful? Mainly for performance reasons. I have some fields that are really large that I would like to have only display on the "find by id" route but not on the "list" route.
EDIT: first pass at "hacking" it in there. I feel like there's probably a better way than putting a "default list projection" on the model but it works: