Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cleanModifiedSubpaths.js 648B

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.startsWith(path + '.')) {
  20. delete doc.$__.activePaths.states.modify[modifiedPath];
  21. ++deleted;
  22. }
  23. }
  24. return deleted;
  25. };