diff --git a/index.js b/index.js index a8d4db8..620b1ea 100644 --- a/index.js +++ b/index.js @@ -29,10 +29,10 @@ module.exports = function(schema) { for (var attribute in updateData) { let isProtectedKey = protectedKeys.indexOf(attribute) > -1; let keyIsArray = Array.isArray(updateData[attribute]); - let isObjectWithKeys = typeof modelInstance[attribute] == 'object' && !keyIsArray && Object.keys(modelInstance[attribute]).length; + let isObjectWithKeys = modelInstance[attribute] !== null && typeof modelInstance[attribute] == 'object' && !keyIsArray && Object.keys(modelInstance[attribute]).length; - let keyIsUpdatable = updateData.hasOwnProperty(attribute) && attribute !== '_id' && !isProtectedKey && !isObjectWithKeys; - let isNestedKey = updateData.hasOwnProperty(attribute) && attribute !== '_id' && !isProtectedKey && isObjectWithKeys; + let keyIsUpdatable = Object.prototype.hasOwnProperty.call(updateData, attribute) && attribute !== '_id' && !isProtectedKey && !isObjectWithKeys; + let isNestedKey = Object.prototype.hasOwnProperty.call(updateData, attribute) && attribute !== '_id' && !isProtectedKey && isObjectWithKeys; if (keyIsUpdatable) modelInstance[attribute] = updateData[attribute];