cleanModifiedSubpaths.js 651 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. /*!
  3. * ignore
  4. */
  5. module.exports = function cleanModifiedSubpaths(doc, path, options) {
  6. options = options || {};
  7. const skipDocArrays = options.skipDocArrays;
  8. let deleted = 0;
  9. if (!doc) {
  10. return deleted;
  11. }
  12. for (const modifiedPath of Object.keys(doc.$__.activePaths.states.modify)) {
  13. if (skipDocArrays) {
  14. const schemaType = doc.schema.path(modifiedPath);
  15. if (schemaType && schemaType.$isMongooseDocumentArray) {
  16. continue;
  17. }
  18. }
  19. if (modifiedPath.indexOf(path + '.') === 0) {
  20. delete doc.$__.activePaths.states.modify[modifiedPath];
  21. ++deleted;
  22. }
  23. }
  24. return deleted;
  25. };