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

fix: set flattenObjectIds to false when calling toObject() for internal purposes #14938

Merged
merged 5 commits into from
Oct 9, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14935

Summary

insertMany() currently respects schema-level flattenObjectIds option settings, which means if schema sets flattenObjectIds: true then Mongoose will store ObjectIds as strings.

This does not affect save() because save() was fixed in #13648, but that issue still affects insertMany().

In general, internalToObjectOptions should always set flattenObjectIds to true because we rely on those options when trying to get the MongoDB server representation of an object for queries, insertMany(), etc.

We should also backport this fix to 6.x and 7.x.

Examples

@vkarpov15 vkarpov15 added this to the 8.7.1 milestone Oct 6, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.7.1, 8.7.2 Oct 8, 2024
test/document.test.js Outdated Show resolved Hide resolved
test/document.test.js Outdated Show resolved Hide resolved
vkarpov15 and others added 2 commits October 9, 2024 11:22
@vkarpov15 vkarpov15 modified the milestones: 8.7.2, 8.7.1 Oct 9, 2024
@vkarpov15 vkarpov15 merged commit d861d21 into master Oct 9, 2024
57 of 58 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14935 branch October 9, 2024 15:25
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.

find on ObjectIds not working after insertMany
2 participants