om/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js

26 lines
613 B
JavaScript
Raw Normal View History

2019-02-01 14:06:44 +01:00
'use strict';
/*!
* ignore
*/
module.exports = function cleanModifiedSubpaths(doc, path, options) {
options = options || {};
const skipDocArrays = options.skipDocArrays;
let deleted = 0;
for (const modifiedPath of Object.keys(doc.$__.activePaths.states.modify)) {
if (skipDocArrays) {
const schemaType = doc.schema.path(modifiedPath);
if (schemaType && schemaType.$isMongooseDocumentArray) {
continue;
}
}
if (modifiedPath.indexOf(path + '.') === 0) {
delete doc.$__.activePaths.states.modify[modifiedPath];
++deleted;
}
}
return deleted;
};