-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
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.