Skip to content

Required array field throws error when set as empty array #2662

@Soviut

Description

@Soviut

I have an array field with the following schema on that field:

parents:
    type: 'Array'
    required: true

When I try to create a document with the following data:

data =
    parents: []

Translation.create data, (err, translations) ->
    console.log err, translations

I get the following error:

ValidationError: Path `parents` is required.

If I put a value inside the array it works, like so:

data =
    parents: ['blah']

Similarly, if I remove the required: true from the schema, it also starts working.

Is an empty array not considered satisfactory for "required" validation? I understand it's false in javascript, but there are plenty of cases where empty arrays and objects are intended in Mongo documents.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions