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

Edits to Handle null objects in arrays during populate operations #13842

Merged
merged 4 commits into from
Sep 8, 2023

Conversation

vkarpov15
Copy link
Collaborator

Summary

#13839 , plus lint fixes and test case

Examples

ZSabakh and others added 3 commits September 8, 2023 00:04
…ed to be populated.

Prior to this change, if there was a wild NULL object in an array within a document, mongoose would attempt to populate it, and would crash. 

For example, if we had a schema containing founders array in such a way - 
  founders: [
    {
      legal_form: { type: mongoose.Schema.Types.ObjectId, ref: "Legal_Form" },
      name: String,
      identification_code: String,
      ownership_percentage: Number,
    },
  ],


and our database contained a document with founders looking like following - 

[
  {
    name: ''name",
    identification_code: ''id_code",
    ownership_percentage: 51.5,
    _id: new ObjectId("63e1fc49d4ff7ce99a3a3faf")
  },
  null
]

Then following error would be thrown - 
TypeError: Cannot read properties of null (reading 'populated')
Handle null objects in arrays during populate operations
Copy link
Collaborator

@IslandRhythms IslandRhythms left a comment

Choose a reason for hiding this comment

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

LGTM

@vkarpov15 vkarpov15 added this to the 7.5.1 milestone Sep 8, 2023
@vkarpov15 vkarpov15 merged commit f552fe2 into master Sep 8, 2023
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-13839 branch September 8, 2023 15:00
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.

3 participants