Skip to content
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

feat: allow default lean options plugin config #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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?

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 ?
2 participants