Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Aggregate.prototype._optionsForExec = function() {
const options = this.options || {};

const asyncLocalStorage = this.model()?.db?.base.transactionAsyncLocalStorage?.getStore();
if (!options.hasOwnProperty('session') && asyncLocalStorage?.session != null) {
if (!Object.hasOwn(options, 'session') && asyncLocalStorage?.session != null) {
options.session = asyncLocalStorage.session;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = function cast(schema, obj, options, context) {
val = cast(schema, val, options, context);
} else if (path === '$text') {
val = castTextSearch(val, path);
} else if (path === '$comment' && !schema.paths.hasOwnProperty('$comment')) {
} else if (path === '$comment' && !Object.hasOwn(schema.paths, '$comment')) {
val = castString(val, path);
obj[path] = val;
} else {
Expand Down
18 changes: 9 additions & 9 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Object.defineProperty(Connection.prototype, 'readyState', {
*/

Connection.prototype.get = function getOption(key) {
if (this.config.hasOwnProperty(key)) {
if (Object.hasOwn(this.config, key)) {
return this.config[key];
}

Expand Down Expand Up @@ -192,7 +192,7 @@ Connection.prototype.get = function getOption(key) {
*/

Connection.prototype.set = function setOption(key, val) {
if (this.config.hasOwnProperty(key)) {
if (Object.hasOwn(this.config, key)) {
this.config[key] = val;
return val;
}
Expand Down Expand Up @@ -459,7 +459,7 @@ Connection.prototype.bulkWrite = async function bulkWrite(ops, options) {

const ordered = options.ordered == null ? true : options.ordered;
const asyncLocalStorage = this.base.transactionAsyncLocalStorage?.getStore();
if ((!options || !options.hasOwnProperty('session')) && asyncLocalStorage?.session != null) {
if ((!options || !Object.hasOwn(options, 'session')) && asyncLocalStorage?.session != null) {
options = { ...options, session: asyncLocalStorage.session };
}

Expand All @@ -477,7 +477,7 @@ Connection.prototype.bulkWrite = async function bulkWrite(ops, options) {
if (op.name == null) {
throw new MongooseError('Must specify operation name in Connection.prototype.bulkWrite()');
}
if (!castBulkWrite.cast.hasOwnProperty(op.name)) {
if (!Object.hasOwn(castBulkWrite.cast, op.name)) {
throw new MongooseError(`Unrecognized bulkWrite() operation name ${op.name}`);
}

Expand Down Expand Up @@ -513,7 +513,7 @@ Connection.prototype.bulkWrite = async function bulkWrite(ops, options) {
results[i] = error;
continue;
}
if (!castBulkWrite.cast.hasOwnProperty(op.name)) {
if (!Object.hasOwn(castBulkWrite.cast, op.name)) {
const error = new MongooseError(`Unrecognized bulkWrite() operation name ${op.name}`);
validationErrors.push({ index: i, error: error });
results[i] = error;
Expand Down Expand Up @@ -772,10 +772,10 @@ async function _wrapUserTransaction(fn, session, mongoose) {
function _resetSessionDocuments(session) {
for (const doc of session[sessionNewDocuments].keys()) {
const state = session[sessionNewDocuments].get(doc);
if (state.hasOwnProperty('isNew')) {
if (Object.hasOwn(state, 'isNew')) {
doc.$isNew = state.isNew;
}
if (state.hasOwnProperty('versionKey')) {
if (Object.hasOwn(state, 'versionKey')) {
doc.set(doc.schema.options.versionKey, state.versionKey);
}

Expand Down Expand Up @@ -1013,7 +1013,7 @@ Connection.prototype.onOpen = function() {
// avoid having the collection subscribe to our event emitter
// to prevent 0.3 warning
for (const i in this.collections) {
if (utils.object.hasOwnProperty(this.collections, i)) {
if (Object.hasOwn(this.collections, i)) {
this.collections[i].onOpen();
}
}
Expand Down Expand Up @@ -1321,7 +1321,7 @@ Connection.prototype.onClose = function onClose(force) {
// avoid having the collection subscribe to our event emitter
// to prevent 0.3 warning
for (const i in this.collections) {
if (utils.object.hasOwnProperty(this.collections, i)) {
if (Object.hasOwn(this.collections, i)) {
this.collections[i].onClose(force);
}
}
Expand Down
39 changes: 22 additions & 17 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ function init(self, obj, doc, opts, prefix) {
}
} else {
// Retain order when overwriting defaults
if (doc.hasOwnProperty(i) && value !== void 0 && !opts.hydratedPopulatedDocs) {
if (Object.hasOwn(doc, i) && value !== void 0 && !opts.hydratedPopulatedDocs) {
delete doc[i];
}
if (value === null) {
Expand Down Expand Up @@ -1156,7 +1156,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
const orderedKeys = Object.keys(this.$__schema.tree);
for (let i = 0, len = orderedKeys.length; i < len; ++i) {
(key = orderedKeys[i]) &&
(this._doc.hasOwnProperty(key)) &&
(Object.hasOwn(this._doc, key)) &&
(orderedDoc[key] = undefined);
}
this._doc = Object.assign(orderedDoc, this._doc);
Expand Down Expand Up @@ -1206,8 +1206,8 @@ Document.prototype.$set = function $set(path, val, type, options) {
return this;
}
const wasModified = this.$isModified(path);
const hasInitialVal = this.$__.savedState != null && this.$__.savedState.hasOwnProperty(path);
if (this.$__.savedState != null && !this.$isNew && !this.$__.savedState.hasOwnProperty(path)) {
const hasInitialVal = this.$__.savedState != null && Object.hasOwn(this.$__.savedState, path);
if (this.$__.savedState != null && !this.$isNew && !Object.hasOwn(this.$__.savedState, path)) {
const initialVal = this.$__getValue(path);
this.$__.savedState[path] = initialVal;

Expand Down Expand Up @@ -1512,7 +1512,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
this.$__.session[sessionNewDocuments].get(this).modifiedPaths &&
!this.$__.session[sessionNewDocuments].get(this).modifiedPaths.has(savedStatePath);
if (savedState != null &&
savedState.hasOwnProperty(savedStatePath) &&
Object.hasOwn(savedState, savedStatePath) &&
(!isInTransaction || isModifiedWithinTransaction) &&
utils.deepEqual(val, savedState[savedStatePath])) {
this.unmarkModified(path);
Expand Down Expand Up @@ -1994,7 +1994,7 @@ Document.prototype.$get = Document.prototype.get;

Document.prototype.$__path = function(path) {
const adhocs = this.$__.adhocPaths;
const adhocType = adhocs && adhocs.hasOwnProperty(path) ? adhocs[path] : null;
const adhocType = adhocs && Object.hasOwn(adhocs, path) ? adhocs[path] : null;

if (adhocType) {
return adhocType;
Expand Down Expand Up @@ -2038,7 +2038,7 @@ Document.prototype.$__saveInitialState = function $__saveInitialState(path) {
if (savedState != null) {
const firstDot = savedStatePath.indexOf('.');
const topLevelPath = firstDot === -1 ? savedStatePath : savedStatePath.slice(0, firstDot);
if (!savedState.hasOwnProperty(topLevelPath)) {
if (!Object.hasOwn(savedState, topLevelPath)) {
savedState[topLevelPath] = clone(this.$__getValue(topLevelPath));
}
}
Expand Down Expand Up @@ -2349,15 +2349,15 @@ Document.prototype.$isDefault = function(path) {
}

if (typeof path === 'string' && path.indexOf(' ') === -1) {
return this.$__.activePaths.getStatePaths('default').hasOwnProperty(path);
return Object.hasOwn(this.$__.activePaths.getStatePaths('default'), path);
}

let paths = path;
if (!Array.isArray(paths)) {
paths = paths.split(' ');
}

return paths.some(path => this.$__.activePaths.getStatePaths('default').hasOwnProperty(path));
return paths.some(path => Object.hasOwn(this.$__.activePaths.getStatePaths('default'), path));
};

/**
Expand Down Expand Up @@ -2411,7 +2411,7 @@ Document.prototype.isDirectModified = function(path) {
}

if (typeof path === 'string' && path.indexOf(' ') === -1) {
const res = this.$__.activePaths.getStatePaths('modify').hasOwnProperty(path);
const res = Object.hasOwn(this.$__.activePaths.getStatePaths('modify'), path);
if (res || path.indexOf('.') === -1) {
return res;
}
Expand Down Expand Up @@ -2450,15 +2450,15 @@ Document.prototype.isInit = function(path) {
}

if (typeof path === 'string' && path.indexOf(' ') === -1) {
return this.$__.activePaths.getStatePaths('init').hasOwnProperty(path);
return Object.hasOwn(this.$__.activePaths.getStatePaths('init'), path);
}

let paths = path;
if (!Array.isArray(paths)) {
paths = paths.split(' ');
}

return paths.some(path => this.$__.activePaths.getStatePaths('init').hasOwnProperty(path));
return paths.some(path => Object.hasOwn(this.$__.activePaths.getStatePaths('init'), path));
};

/**
Expand Down Expand Up @@ -2596,7 +2596,7 @@ Document.prototype.isDirectSelected = function isDirectSelected(path) {
return true;
}

if (this.$__.selected.hasOwnProperty(path)) {
if (Object.hasOwn(this.$__.selected, path)) {
return inclusive;
}

Expand Down Expand Up @@ -2772,7 +2772,7 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
if (doc.$isModified(fullPathToSubdoc, null, modifiedPaths) &&
// Avoid using isDirectModified() here because that does additional checks on whether the parent path
// is direct modified, which can cause performance issues re: gh-14897
!subdocParent.$__.activePaths.getStatePaths('modify').hasOwnProperty(fullPathToSubdoc) &&
!Object.hasOwn(subdocParent.$__.activePaths.getStatePaths('modify'), fullPathToSubdoc) &&
!subdocParent.$isDefault(fullPathToSubdoc)) {
paths.add(fullPathToSubdoc);

Expand Down Expand Up @@ -2843,7 +2843,12 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
// Single nested paths (paths embedded under single nested subdocs) will
// be validated on their own when we call `validate()` on the subdoc itself.
// Re: gh-8468
Object.keys(flat).filter(path => !doc.$__schema.singleNestedPaths.hasOwnProperty(path)).forEach(addToPaths);
const singleNestedPaths = doc.$__schema.singleNestedPaths;
for (const path of Object.keys(flat)) {
if (!Object.hasOwn(singleNestedPaths, path)) {
addToPaths(path);
}
}
}
}

Expand Down Expand Up @@ -4184,7 +4189,7 @@ function applyVirtuals(self, json, options, toObjectOptions) {
}

// Allow skipping aliases with `toObject({ virtuals: true, aliases: false })`
if (!aliases && schema.aliases.hasOwnProperty(path)) {
if (!aliases && Object.hasOwn(schema.aliases, path)) {
continue;
}

Expand Down Expand Up @@ -5097,7 +5102,7 @@ function checkDivergentArray(doc, path, array) {
// would be similarly destructive as we never received all
// elements of the array and potentially would overwrite data.
const check = pop.options.match ||
pop.options.options && utils.object.hasOwnProperty(pop.options.options, 'limit') || // 0 is not permitted
pop.options.options && Object.hasOwn(pop.options.options, 'limit') || // 0 is not permitted
pop.options.options && pop.options.options.skip || // 0 is permitted
pop.options.select && // deselected _id?
(pop.options.select._id === 0 ||
Expand Down
4 changes: 2 additions & 2 deletions lib/drivers/node-mongodb-native/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ NativeConnection.prototype.useDb = function(name, options) {
function wireup() {
newConn.client = _this.client;
const _opts = {};
if (options.hasOwnProperty('noListener')) {
if (Object.hasOwn(options, 'noListener')) {
_opts.noListener = options.noListener;
}
newConn.db = _this.client.db(name, _opts);
Expand Down Expand Up @@ -515,7 +515,7 @@ function _setClient(conn, client, options, dbName) {
conn.onOpen();

for (const i in conn.collections) {
if (utils.object.hasOwnProperty(conn.collections, i)) {
if (Object.hasOwn(conn.collections, i)) {
conn.collections[i].onOpen();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function flatten(update, path, options, schema) {
if (isNested) {
const paths = Object.keys(schema.paths);
for (const p of paths) {
if (p.startsWith(path + key + '.') && !result.hasOwnProperty(p)) {
if (p.startsWith(path + key + '.') && !Object.hasOwn(result, p)) {
result[p] = void 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/indexes/applySchemaCollation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function applySchemaCollation(indexKeys, indexOptions, schemaOp
return;
}

if (schemaOptions.hasOwnProperty('collation') && !indexOptions.hasOwnProperty('collation')) {
if (Object.hasOwn(schemaOptions, 'collation') && !Object.hasOwn(indexOptions, 'collation')) {
indexOptions.collation = schemaOptions.collation;
}
};
2 changes: 1 addition & 1 deletion lib/helpers/indexes/isDefaultIdIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ module.exports = function isDefaultIdIndex(index) {
}

const key = get(index, 'key', {});
return Object.keys(key).length === 1 && key.hasOwnProperty('_id');
return Object.keys(key).length === 1 && Object.hasOwn(key, '_id');
};
2 changes: 1 addition & 1 deletion lib/helpers/model/applyMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function applyMethods(model, schema) {
}
for (const method of Object.keys(schema.methods)) {
const fn = schema.methods[method];
if (schema.tree.hasOwnProperty(method)) {
if (Object.hasOwn(schema.tree, method)) {
throw new Error('You have a method and a property in your schema both ' +
'named "' + method + '"');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/model/castBulkWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function _addDiscriminatorToObject(schema, obj) {

function decideModelByObject(model, object) {
const discriminatorKey = model.schema.options.discriminatorKey;
if (object != null && object.hasOwnProperty(discriminatorKey)) {
if (object != null && Object.hasOwn(object, discriminatorKey)) {
model = getDiscriminatorByValue(model.discriminators, object[discriminatorKey]) || model;
}
return model;
Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/populate/getModelsMapForPopulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ function _virtualPopulate(model, docs, options, _virtualRes) {
}
data.count = virtual.options.count;

if (virtual.options.skip != null && !options.hasOwnProperty('skip')) {
if (virtual.options.skip != null && !Object.hasOwn(options, 'skip')) {
options.skip = virtual.options.skip;
}
if (virtual.options.limit != null && !options.hasOwnProperty('limit')) {
if (virtual.options.limit != null && !Object.hasOwn(options, 'limit')) {
options.limit = virtual.options.limit;
}
if (virtual.options.perDocumentLimit != null && !options.hasOwnProperty('perDocumentLimit')) {
if (virtual.options.perDocumentLimit != null && !Object.hasOwn(options, 'perDocumentLimit')) {
options.perDocumentLimit = virtual.options.perDocumentLimit;
}
let foreignField = virtual.options.foreignField;
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/populate/modelNamesFromRefPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
const refValue = mpath.get(refPath, doc, lookupLocalFields);

let modelNames;
if (modelSchema != null && modelSchema.virtuals.hasOwnProperty(refPath)) {
if (modelSchema != null && Object.hasOwn(modelSchema.virtuals, refPath)) {
modelNames = [modelSchema.virtuals[refPath].applyGetters(void 0, doc)];
} else {
modelNames = Array.isArray(refValue) ? refValue : [refValue];
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/populate/removeDeselectedForeignField.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function removeDeselectedForeignField(foreignFields, options, d
return;
}
for (const foreignField of foreignFields) {
if (!projection.hasOwnProperty('-' + foreignField)) {
if (!Object.hasOwn(projection, '-' + foreignField)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/projection/applyProjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function applyExclusiveProjection(doc, projection, hasIncludedChildren, projecti

for (const key of Object.keys(ret)) {
const fullPath = prefix ? prefix + '.' + key : key;
if (projection.hasOwnProperty(fullPath) || projectionLimb.hasOwnProperty(key)) {
if (Object.hasOwn(projection, fullPath) || Object.hasOwn(projectionLimb, key)) {
if (isPOJO(projection[fullPath]) || isPOJO(projectionLimb[key])) {
ret[key] = applyExclusiveProjection(ret[key], projection, hasIncludedChildren, projectionLimb[key], fullPath);
} else {
Expand All @@ -68,7 +68,7 @@ function applyInclusiveProjection(doc, projection, hasIncludedChildren, projecti

for (const key of Object.keys(ret)) {
const fullPath = prefix ? prefix + '.' + key : key;
if (projection.hasOwnProperty(fullPath) || projectionLimb.hasOwnProperty(key)) {
if (Object.hasOwn(projection, fullPath) || Object.hasOwn(projectionLimb, key)) {
if (isPOJO(projection[fullPath]) || isPOJO(projectionLimb[key])) {
ret[key] = applyInclusiveProjection(ret[key], projection, hasIncludedChildren, projectionLimb[key], fullPath);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/query/getEmbeddedDiscriminatorPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, p
const schemaKey = updatedPathsByFilter[filterKey] + '.' + key;
const arrayFilterKey = filterKey + '.' + key;
if (schemaKey === discriminatorFilterPath) {
const filter = arrayFilters.find(filter => filter.hasOwnProperty(arrayFilterKey));
const filter = arrayFilters.find(filter => Object.hasOwn(filter, arrayFilterKey));
if (filter != null) {
discriminatorKey = filter[arrayFilterKey];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/setDefaultsOnInsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ function pathExistsInUpdate(update, targetPath, pathPieces) {
}

// Check exact match
if (update.hasOwnProperty(targetPath)) {
if (Object.hasOwn(update, targetPath)) {
return true;
}

// Check if any parent path exists
let cur = pathPieces[0];
for (let i = 1; i < pathPieces.length; ++i) {
if (update.hasOwnProperty(cur)) {
if (Object.hasOwn(update, cur)) {
return true;
}
cur += '.' + pathPieces[i];
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/timestamps/setupTimestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function setupTimestamps(schema, timestamps) {
}
const createdAt = handleTimestampOption(timestamps, 'createdAt');
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
const currentTime = timestamps != null && timestamps.hasOwnProperty('currentTime') ?
const currentTime = timestamps != null && Object.hasOwn(timestamps, 'currentTime') ?
timestamps.currentTime :
null;
const schemaAdditions = {};
Expand Down
Loading