function iter(i, v) {
    const schemaPath = schema._getSchema(updates[i]);
    if (schemaPath == null) {
      return;
    }
    if (schemaPath.instance === 'Mixed' && schemaPath.path !== updates[i]) {
      return;
    }

    if (v && Array.isArray(v.$in)) {
      v.$in.forEach((v, i) => {
        validatorsToExecute.push(function(callback) {
          schemaPath.doValidate(
            v,
            function(err) {
              if (err) {
                err.path = updates[i] + '.$in.' + i;
                validationErrors.push(err);
              }
              callback(null);
            },
            context,
            { updateValidator: true });
        });
      });
    } else {
      if (isPull[updates[i]] &&
          schemaPath.$isMongooseArray) {
        return;
      }

      if (schemaPath.$isMongooseDocumentArrayElement && v != null && v.$__ != null) {
        alreadyValidated.push(updates[i]);
        validatorsToExecute.push(function(callback) {
          schemaPath.doValidate(v, function(err) {
            if (err) {
              if (err.errors) {
                for (const key of Object.keys(err.errors)) {
                  const _err = err.errors[key];
                  _err.path = updates[i] + '.' + key;
                  validationErrors.push(_err);
                }
              } else {
                err.path = updates[i];
                validationErrors.push(err);
              }
            }

            return callback(null);
          }, context, { updateValidator: true });
        });
      } else {
        validatorsToExecute.push(function(callback) {
          for (const path of alreadyValidated) {
            if (updates[i].startsWith(path + '.')) {
              return callback(null);
            }
          }
          if (schemaPath.$isSingleNested) {
            alreadyValidated.push(updates[i]);
          }

          schemaPath.doValidate(v, function(err) {
            if (schemaPath.schema != null &&
                schemaPath.schema.options.storeSubdocValidationError === false &&
                err instanceof ValidationError) {
              return callback(null);
            }

            if (err) {
              err.path = updates[i];
              validationErrors.push(err);
            }
            callback(null);
          }, context, { updateValidator: true });
        });
      }
    }
  }
Applies validators and defaults to update and findOneAndUpdate operations,
specifically passing a null doc as `this` to validators and defaults

@param {Query} query
@param {Schema} schema
@param {Object} castedDoc
@param {Object} options
@method runValidatorsOnUpdate
@api private