Skip to content

fix(model): remove unnecessary conversion of undefined -> null in findById - #15566

Merged
vkarpov15 merged 1 commit into
masterfrom
vkarpov15/gh-15551
Aug 5, 2025
Merged

vkarpov15 merged 1 commit into
masterfrom
vkarpov15/gh-15551

Conversation

@vkarpov15

Copy link
Copy Markdown
Collaborator

Fix #15551

Summary

The findById() documentation indicates that findOne({ _id: undefined }) will return an arbitrary document, which is no longer accurate. I also removed the undefined check in findById(), which is no longer necessary because findOne({ _id: undefined }) no longer returns an arbitrary document.

Examples

@vkarpov15 vkarpov15 added this to the 8.17.1 milestone Aug 4, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes unnecessary undefined handling in the findById() method and updates its documentation to reflect current behavior. The change eliminates a conversion that was previously needed when findOne({ _id: undefined }) returned arbitrary documents, which is no longer the case.

  • Remove conditional check that converts undefined to null in findById()
  • Update documentation to reflect that findById(id) is now equivalent to findOne({ _id: id })
  • Remove outdated documentation explaining the difference in undefined handling between the two methods

Comment thread lib/model.js Resolved
@vkarpov15
vkarpov15 merged commit 39b4f37 into master Aug 5, 2025
@hasezoey
hasezoey deleted the vkarpov15/gh-15551 branch August 6, 2025 09:08
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.

findOne({ someField: undefined }) and findOne({ _id: undefined }) do NOT behave like findOne({})

3 participants