Skip to content

fix(clone): fix parent doc for map subdocuments and array subdocuments#15958

Merged
vkarpov15 merged 4 commits intomasterfrom
fix/clone-edge-cases
Jan 13, 2026
Merged

fix(clone): fix parent doc for map subdocuments and array subdocuments#15958
vkarpov15 merged 4 commits intomasterfrom
fix/clone-edge-cases

Conversation

@AbdelrahmanHafez
Copy link
Collaborator

Fixes #15954

re #15901 #15904

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes parent document references when cloning documents with Map subdocuments and array subdocuments. The changes ensure that cloned subdocuments properly point to their cloned parent structures rather than the original ones.

Changes:

  • Added special handling for MongooseMap cloning to properly set parent references
  • Fixed parentArray references for cloned array subdocuments to point to the cloned array
  • Added options object isolation for document arrays to prevent reference pollution

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/helpers/clone.js Added MongooseMap cloning logic and fixed parentArray handling for document arrays
test/document.test.js Added comprehensive test suite covering Map subdocuments, array subdocuments, deleteOne isolation, and nested array scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AbdelrahmanHafez AbdelrahmanHafez marked this pull request as ready for review January 12, 2026 00:24
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@vkarpov15 vkarpov15 merged commit 56abc82 into master Jan 13, 2026
56 checks passed
@vkarpov15 vkarpov15 added this to the 9.1.4 milestone Jan 13, 2026
@hasezoey hasezoey deleted the fix/clone-edge-cases branch January 13, 2026 15:19
vkarpov15 added a commit that referenced this pull request Jan 13, 2026
fix(clone): fix parent doc for map subdocuments and array subdocuments
vkarpov15 added a commit that referenced this pull request Jan 23, 2026
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.

[Bug]: $clone() with Map subdocs, and parentArray() point to original document

3 participants