-
- Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
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[]
const removeSufix = (name: string) => { return name.slice(0, -6); };this is the current result of two console.logs in sequence
console.log(user.hobbies); // ["swimming", "football"] => correct value console.log(user.hobbies); // ["sw", "fo"] => runs getter againSteps to Reproduce
https://github.com/dantenol/mongoose-array-getters-demo
Expected Behavior
Run the getter function only once.
Metadata
Metadata
Assignees
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.