mongoose 8.19.3 → 8.19.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/model.js CHANGED
@@ -1318,7 +1318,11 @@ Model.syncIndexes = async function syncIndexes(options) {
1318
1318
  throw new MongooseError('Model.syncIndexes() no longer accepts a callback');
1319
1319
  }
1320
1320
 
1321
- const autoCreate = options?.autoCreate ?? this.schema.options?.autoCreate ?? this.db.config.autoCreate ?? true;
1321
+ const autoCreate = options?.autoCreate ??
1322
+ this.schema.options?.autoCreate ??
1323
+ this.db.config.autoCreate ??
1324
+ this.db.base?.options?.autoCreate ??
1325
+ true;
1322
1326
 
1323
1327
  if (autoCreate) {
1324
1328
  try {
@@ -3076,6 +3080,8 @@ Model.$__insertMany = function(arr, options, callback) {
3076
3080
  () => { callback(null, doc); },
3077
3081
  error => {
3078
3082
  if (ordered === false) {
3083
+ // Add index to validation error so users can identify which document failed
3084
+ error.index = index;
3079
3085
  validationErrors.push(error);
3080
3086
  validationErrorsToOriginalOrder.set(error, index);
3081
3087
  results[index] = error;
package/lib/schema.js CHANGED
@@ -1694,6 +1694,10 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
1694
1694
  `\`${name}\` is not a valid type within the array \`${path}\`.` +
1695
1695
  'See https://bit.ly/mongoose-schematypes for a list of valid schema types.');
1696
1696
  }
1697
+
1698
+ if (name === 'Union' && typeof cast === 'object') {
1699
+ cast.parentSchema = this;
1700
+ }
1697
1701
  }
1698
1702
 
1699
1703
  return new MongooseTypes.Array(path, cast || MongooseTypes.Mixed, obj, options);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.19.3",
4
+ "version": "8.19.4",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
package/types/error.d.ts CHANGED
@@ -91,6 +91,9 @@ declare module 'mongoose' {
91
91
  errors: { [path: string]: ValidatorError | CastError };
92
92
  addError: (path: string, error: ValidatorError | CastError) => void;
93
93
 
94
+ /** Index of the document in insertMany() that failed validation (only set for unordered insertMany) */
95
+ index?: number;
96
+
94
97
  constructor(instance?: MongooseError);
95
98
  }
96
99
 
package/types/models.d.ts CHANGED
@@ -20,7 +20,7 @@ declare module 'mongoose' {
20
20
  name: string | number,
21
21
  schema: Schema<T, U>,
22
22
  value?: string | number | ObjectId | DiscriminatorOptions
23
- ): U;
23
+ ): Model<U>;
24
24
  }
25
25
 
26
26
  export type MongooseBulkWriteResult = mongodb.BulkWriteResult & {
@@ -97,7 +97,7 @@ declare module 'mongoose' {
97
97
 
98
98
  /**
99
99
  * If true, attach a required validator to this path, which ensures this path
100
- * path cannot be set to a nullish value. If a function, Mongoose calls the
100
+ * cannot be set to a nullish value. If a function, Mongoose calls the
101
101
  * function and only checks for nullish values if the function returns a truthy value.
102
102
  */
103
103
  required?: