src/mongoose.js
// remove the key from the doc if the value is undefined
remove the key from the doc if the value is undefined
remove the key from the doc if the value is undefined
function unsetUndefined(next) {
  const query = this;
  if (['findOneAndUpdate', 'update', 'updateMany'].includes(this.op)) {
    this._update = this._update || {};
    Object.keys(this._update).forEach(k => {
      if (query._update[k] === undefined) {
        delete query._update[k];
        if (!query._update.$unset) query._update.$unset = {};
        query._update.$unset[k] = true;
      }
    });
  } else {
    logger.warn('mongoose hook ignoring unhandled `op`:', this.op, '\n', this);
  }
  next();
}
function unsetUndefined ( next ) { const query = this ; if ( [ 'findOneAndUpdate' , 'update' , 'updateMany' ] . includes ( this . op ) ) { this . _update = this . _update || { } ; Object . keys ( this . _update ) . forEach ( k => { if ( query . _update [ k ] === undefined ) { delete query . _update [ k ] ; if ( ! query . _update . $unset ) query . _update . $unset = { } ; query . _update . $unset [ k ] = true ; } } ) ; } else { logger . warn ( 'mongoose hook ignoring unhandled `op`:' , this . op , '\n' , this ) ; } next ( ) ; }
remove the key from the doc if the value is undefined
remove the key from the doc if the value is undefined