Automattic/mongoose · error · TypeError

Invalid value for schema Array path `${fullPath}`, got value

Error message

Invalid value for schema Array path `${fullPath}`, got value "${val[0]}"

What it means

Error "Invalid value for schema Array path `${fullPath}`, got value "${val[0]}"" thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:841

      const upperVal = val.charAt(0).toUpperCase() + val.substring(1);
      isMongooseTypeString = MongooseTypes[upperVal] != null;
    }
    if (
      key !== '_id' &&
      ((typeof val !== 'object' && typeof val !== 'function' && !isMongooseTypeString) ||
      val == null)
    ) {
      throw new TypeError(`Invalid schema configuration: \`${val}\` is not ` +
        `a valid type at path \`${key}\`. See ` +
        'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
    }
    if (val instanceof VirtualType || (val.constructor?.name ?? null) === 'VirtualType') {
      this.virtual(val);
      continue;
    }

    if (Array.isArray(val) && val.length === 1 && val[0] == null) {
      throw new TypeError('Invalid value for schema Array path `' + fullPath +
        '`, got value "' + val[0] + '"');
    }

    if (!(isPOJO(val) || val instanceof SchemaTypeOptions)) {
      // Special-case: Non-options definitely a path so leaf at this node
      // Examples: Schema instances, SchemaType instances
      if (prefix) {
        this.nested[prefix.substring(0, prefix.length - 1)] = true;
      }
      this.path(prefix + key, val);
      if (!val[0]?.instanceOfSchema && utils.isPOJO(val[0]?.discriminators)) {
        const schemaType = this.path(prefix + key);
        for (const key in val[0].discriminators) {
          schemaType.discriminator(key, val[0].discriminators[key]);
        }
      }
    } else if (utils.hasOwnKeys(val) === false) {
      // Special-case: {} always interpreted as Mixed path so leaf at this node

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/schema.js:841 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21). Data as JSON: /api/errors/daac08e618cdf2e6. Report an issue: GitHub.