-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Getter firing every time on array property #13748
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
Well that it gets called everytime makes sense. That it slices everytime not, because strings as all primitives are immutable. |
Can you call |
type is always therefore, changing to the suggested code to force a string had the same results |
vkarpov15
added
the
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
label
Aug 21, 2023
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Aug 23, 2023
vkarpov15
added a commit
that referenced
this issue
Aug 23, 2023
vkarpov15
added a commit
that referenced
this issue
Aug 25, 2023
vkarpov15
added a commit
that referenced
this issue
Aug 28, 2023
fix(document): make array getters avoid unintentionally modifying array, defer getters until index access instead
vkarpov15
added a commit
that referenced
this issue
Aug 28, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
7.4.3
Node.js version
18.17
MongoDB server version
6.0.6
Typescript version (if applicable)
5.1.6
Description
While using getters on a schema with type array, the getter function is called every time the value is accessed. The expected behavior should be run the function only once.
Given this getter function on user.hobbies[]
this is the current result of two console.logs in sequence
Steps to Reproduce
https://github.com/dantenol/mongoose-array-getters-demo
Expected Behavior
Run the getter function only once.
The text was updated successfully, but these errors were encountered: