New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mongoose.SchemaType.get() and .set() : custom getters/setters across all instances of a schematype #6912

Open
vkarpov15 opened this Issue Aug 22, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@vkarpov15
Collaborator

vkarpov15 commented Aug 22, 2018

Re discussion on #6849

Example:

mongoose.Schema.Date.set(v => v === '' ? Date.now() : v); // Convert '' to `new Date()` for all date paths

@vkarpov15 vkarpov15 added this to the 5.x Unprioritized milestone Aug 22, 2018

@vkarpov15 vkarpov15 modified the milestones: 5.x Unprioritized, 5.4 Oct 29, 2018

@vkarpov15 vkarpov15 changed the title from Schema type setters to Support mongoose.SchemaType.get() and .set() : custom getters/setters across all instances of a schematype Oct 29, 2018

@Lanfei

This comment has been minimized.

Lanfei commented Oct 31, 2018

@vkarpov15 What if I want to get the original object in some cases?

@vkarpov15

This comment has been minimized.

Collaborator

vkarpov15 commented Nov 5, 2018

@Lanfei can you provide an example case? You can do something like toObject({ getters: false }) to get the raw doc without any getters applied.

@Lanfei

This comment has been minimized.

Lanfei commented Nov 7, 2018

@vkarpov15 Actually I don't have any example case now, just wanted to know the solution if I met this situation in the future :)

Maybe we can also have something like .get(key, { getter: false })?

@vkarpov15

This comment has been minimized.

Collaborator

vkarpov15 commented Nov 10, 2018

Love it, great idea 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment