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 613B

12345678910111213141516171819202122232425
  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. for (const modifiedPath of Object.keys(doc.$__.activePaths.states.modify)) {
  10. if (skipDocArrays) {
  11. const schemaType = doc.schema.path(modifiedPath);
  12. if (schemaType && schemaType.$isMongooseDocumentArray) {
  13. continue;
  14. }
  15. }
  16. if (modifiedPath.indexOf(path + '.') === 0) {
  17. delete doc.$__.activePaths.states.modify[modifiedPath];
  18. ++deleted;
  19. }
  20. }
  21. return deleted;
  22. };