Skip to content

feat: allow default lean options plugin config #41

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

Merged
merged 4 commits into from
Feb 17, 2025

Conversation

DesignByOnyx
Copy link

Summary

This allows setting { getters: true } at a plugin level. This can be overridden at call time to disable getters if need be. Closes #33.

Examples

const testSchema = new mongoose.Schema({
  field: {
    type: String,
    get(val) { return `${val}-suffix`; },
  }
});
testSchema.plugin(mongooseLeanGetters, { defaultLeanOptions: { getters: true } });

const TestModel = mongoose.model('gh-33', testSchema);
const entry = await TestModel.create({ field: 'value' });
const doc1 = await TestModel.findById(entry._id).lean();
assert.equal(doc1.field, 'value-suffix');

const doc2 = await TestModel.findById(entry._id).lean({ getters: false });
assert.equal(doc2.field, 'value');

@Bderdot
Copy link

Bderdot commented Nov 8, 2024

Hi,

I'm very interested by such feature. Any clue when it would release?

Copy link
Member

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Very sorry for the delay in reviewing this, this got lost in our inbox.

@vkarpov15 vkarpov15 merged commit 5f7065d into mongoosejs:master Feb 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to set getter:true by default ?
3 participants