Skip to content

Getter firing every time on array property #13748

@dantenol

Description

@dantenol

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 again

Steps to Reproduce

https://github.com/dantenol/mongoose-array-getters-demo

Expected Behavior

Run the getter function only once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions