Skip to content

SchemaBuffer does not expose enumValues like String and Number enums #15845

@Anuj-Chhajed

Description

@Anuj-Chhajed

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

v9.0.0

Node.js version

v20.19.4

MongoDB server version

6.0

Typescript version (if applicable)

No response

Description

SchemaBuffer does not expose an enumValues property, even though it accepts enum definitions and performs enum validation. This makes buffer enums inconsistent with SchemaString and SchemaNumber, both of which expose enumValues and support additive .enum() calls.

The result is that applications cannot introspect allowed enum values for buffer fields in the same way they can for string or number enums.

Steps to Reproduce

const mongoose = require('mongoose');
const { Schema } = mongoose;

const schema = new Schema({
  buf: { type: Buffer, enum: [Buffer.from('a'), Buffer.from('b')] }
});

console.log(schema.path('buf').enumValues);
// Expected:
// [<Buffer 61>, <Buffer 62>]

// Actual:
// undefined

SchemaString and SchemaNumber both correctly set enumValues when enum options are provided. SchemaBuffer does not, even though validation works.

Expected Behavior

`SchemaBuffer` should provide an `enumValues` array containing the allowed values (cast to `Buffer`), just like `SchemaString` and `SchemaNumber`.

It should also support:
- `path.enumValues` introspection
- additive `.enum(v1, v2)`
- object syntax (`{ values, message }`)
- consistent enum validation behavior

This keeps all built-in schema types aligned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions