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

_id: false has no meaning #14194

Closed
2 tasks done
332lfgb6 opened this issue Dec 23, 2023 · 1 comment · Fixed by #14195
Closed
2 tasks done

_id: false has no meaning #14194

332lfgb6 opened this issue Dec 23, 2023 · 1 comment · Fixed by #14195
Milestone

Comments

@332lfgb6
Copy link

332lfgb6 commented Dec 23, 2023

Prerequisites

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

Mongoose version

8.0.3

Node.js version

20.10.0

MongoDB server version

4

Typescript version (if applicable)

No response

Description

I specify _id: false because I want to customize the primary key, but I still get an error when model.save(): MongooseError: document must have an _id before save, this is not a contradiction, when I specify _id: false, save should not have this error,otherwise, id: false loses its meaning.
image

Steps to Reproduce

  1. _id: false
  2. model.create or save

Expected Behavior

When id:false is specified, presave does not need to check the _id

@vkarpov15
Copy link
Collaborator

Unfortunately MongoDB doesn't allow you to save a document without an _id. MongoDB will create an _id property for you when you create a document, even if you don't specify one. We should update our docs to specify that the _id option is only useful for subdocuments.

vkarpov15 added a commit that referenced this issue Dec 26, 2023
vkarpov15 added a commit that referenced this issue Dec 27, 2023
docs: clarify disabling `_id` on subdocs
@vkarpov15 vkarpov15 added this to the 8.0.4 milestone Dec 27, 2023
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 a pull request may close this issue.

2 participants