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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global option to disable id virtual for all schemas by default #11966

Closed
2 tasks done
vkarpov15 opened this issue Jun 21, 2022 · 0 comments 路 Fixed by #12067
Closed
2 tasks done

Global option to disable id virtual for all schemas by default #11966

vkarpov15 opened this issue Jun 21, 2022 · 0 comments 路 Fixed by #12067
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

Schemas have an id virtual by default. This virtual returns the _id as a string. While useful in some cases, in many cases I'd like to disable it for all schemas.

Motivation

The id virtual is unnecessary for many applications. It would be helpful to have a way to disable it for the whole app by default, rather than adding id: false for every schema, or having to write a plugin.

Example

mongoose.set('id', false);

const Test = mongoose.model('Test', Schema({ name: String }));
const doc = new Test({});
doc.id; // undefined
@vkarpov15 vkarpov15 added new feature This change adds new functionality, like a new method or class enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature labels Jun 21, 2022
@vkarpov15 vkarpov15 added this to the 6.5 milestone Jun 21, 2022
@IslandRhythms IslandRhythms linked a pull request Jul 7, 2022 that will close this issue
vkarpov15 added a commit that referenced this issue Jul 20, 2022
added global `id` option to disable id on schemas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant