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

setDefaultsOnInsert behaviors as default to true, is it expected? #10643

Closed
yz-ark7 opened this issue Aug 30, 2021 · 1 comment
Closed

setDefaultsOnInsert behaviors as default to true, is it expected? #10643

yz-ark7 opened this issue Aug 30, 2021 · 1 comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@yz-ark7
Copy link

yz-ark7 commented Aug 30, 2021

Hi,

This will be a simple question, so I didn't follow the template. The background is that we upgrade mongoose recently and discovered that the setDefaultsOnInsert is acting as default to be true. After dig into the code, figured on this line, i.e.

if (!options.upsert || shouldSetDefaultsOnInsert === false) {
    return castedDoc;
}

The strict === false check makes the value to be undefined and jump out of the if block. Is it expected?

Also, I figured that I can do mongoose.set('setDefaultsOnInsert', false) to toggle the default behavior. But reading through https://mongoosejs.com/docs/defaults.html , it makes feel the default behavior is false. Caused a bit of confusion.

Thanks!

@IslandRhythms IslandRhythms added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Aug 30, 2021
@vkarpov15 vkarpov15 added this to the 6.0.4 milestone Sep 1, 2021
@vkarpov15 vkarpov15 added docs This issue is due to a mistake or omission in the mongoosejs.com documentation and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Sep 1, 2021
@vkarpov15
Copy link
Collaborator

Yep that if statement is correct, it means we go through with setting defaults on insert unless setDefaultsOnInsert: false.

mongoose.set('setDefaultsOnInsert', false) should disable setDefaultsOnInsert globally, we're updating the docs you linked to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants