Skip to content

Conversation

@AbdelrahmanHafez
Copy link
Collaborator

Port #15866 to 8.x

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 PR refactors the codebase to use the modern Object.hasOwn() API instead of the legacy Object.prototype.hasOwnProperty.call() and .hasOwnProperty() patterns. This is a port of #15866 to the 8.x branch, bringing consistency and modernization to property existence checks across the codebase.

Key changes:

  • Replaced all instances of .hasOwnProperty() and Object.prototype.hasOwnProperty.call() with Object.hasOwn()
  • Removed the custom utility function exports.object.hasOwnProperty from lib/utils.js
  • Applied optional chaining (?.) in some locations to simplify null checks

Reviewed changes

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

Show a summary per file
File Description
lib/virtualType.js Updated property check to use Object.hasOwn()
lib/utils.js Removed deprecated hasOwnProperty utility function and updated hasUserDefinedProperty
lib/types/objectid.js Updated prototype property check
lib/types/documentArray/index.js Converted proxy handler property checks and added optional chaining
lib/types/array/index.js Converted proxy handler property checks and added optional chaining
lib/schemaType.js Updated constructor and instance property checks
lib/schema/array.js Updated type checking logic
lib/schema.js Converted numerous property existence checks across schema operations
lib/query.js Updated option and discriminator key checks
lib/mongoose.js Updated model caching checks and added optional chaining
lib/model.js Updated session option checks and hook context checks
lib/helpers/update/decorateUpdateWithVersionKey.js Simplified hasKey helper function
lib/helpers/update/applyTimestampsToUpdate.js Updated timestamp update checks
lib/helpers/timestamps/setupTimestamps.js Updated currentTime option check
lib/helpers/setDefaultsOnInsert.js Updated path existence checks
lib/helpers/query/getEmbeddedDiscriminatorPath.js Updated array filter checks
lib/helpers/projection/applyProjection.js Updated projection property checks
lib/helpers/populate/*.js Updated various populate-related property checks
lib/helpers/model/castBulkWrite.js Updated discriminator key check
lib/helpers/model/applyMethods.js Updated method conflict check
lib/helpers/indexes/*.js Updated index-related property checks
lib/helpers/common.js Updated nested path check
lib/drivers/node-mongodb-native/connection.js Updated option and collection property checks
lib/document.js Extensive updates to property checks and refactored filter chain to for loop
lib/connection.js Updated config, session, and collection property checks
lib/cast.js Updated schema path check
lib/aggregate.js Updated session option check

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

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.

2 participants