Skip to content

Unordered insertMany drops per-document validation errors when rawResult is false #15771

@MOHITKOURAV01

Description

@MOHITKOURAV01

Prerequisites

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

Mongoose version

6.13.1

Node.js version

14.21.3

MongoDB server version

5.0.26

Typescript version (if applicable)

4.8.4

Description

Calling insertMany() with ordered=false and rawResult=false silently drops the per-document validation errors. You only get the successfully inserted docs (or a driver error), so there’s no way to tell which documents failed validation without re-running the entire batch.

Steps to Reproduce

const schema = new Schema({ name: { type: String, required: true }, year: Number });
const Movie = mongoose.model('Movie', schema);

await Movie.insertMany([
{ foo: 'invalid 1' },
{ name: 'valid movie' },
{ bar: 'invalid 2' }
], { ordered: false });
// Promise resolves with [ { name: 'valid movie' } ]
// but there is no information about the two invalid docs

Expected Behavior

Even when rawResult=false, the resolved docs (or thrown error) should expose mongoose.validationErrors/results so callers can identify which indexes failed validation, similar to the rawResult behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions