index.js
function reformatUpdateProperty(next) {
    const document = this._update['$set'];

    if (document) {
      paths.forEach(function(path) {
        try {
          const splitted = path.path.split('.');
          const key      = splitted.shift();

          if (document[key] === undefined) { return; }

          const value   = determineValue(splitted, document[key]);

          document[key] = nest(splitted, value);
        } catch (error) { return next(error); }
      });
    }

    next();
  }
function reformatUpdateProperty(next) {
    const document = this._update['$set'];

    if (document) {
      paths.forEach(function(path) {
        try {
          const splitted = path.path.split('.');
          const key      = splitted.shift();

          if (document[key] === undefined) { return; }

          const value   = determineValue(splitted, document[key]);

          document[key] = nest(splitted, value);
        } catch (error) { return next(error); }
      });
    }

    next();
  }
function reformatUpdateProperty ( next ) { const document = this . _update [ '$set' ] ; if ( document ) { paths . forEach ( function ( path ) { try { const splitted = path . path . split ( '.' ) ; const key = splitted . shift ( ) ; if ( document [ key ] === undefined ) { return ; } const value = determineValue ( splitted , document [ key ] ) ; document [ key ] = nest ( splitted , value ) ; } catch ( error ) { return next ( error ) ; } } ) ; } next ( ) ; }
If a document is modified, this method will locate the value on updates and assign it to the
appropriate property, allowing for proper validations later.
@param <Function>: next - function that notifies mongoose this middleware is complete
If a document is modified this method will locate the value on updates and assign it to the appropriate property allowing for proper validations later .