mongoose 8.24.3 → 8.24.5

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.
@@ -46,6 +46,11 @@ module.exports = function mergeDiscriminatorSchema(to, from, path, seen) {
46
46
  if (specialProperties.has(key)) {
47
47
  continue;
48
48
  }
49
+ if (key === 'parentSchema') {
50
+ // Skip parentSchema to avoid merging parent schema multiple times
51
+ // through child paths' back-references (gh-15966)
52
+ continue;
53
+ }
49
54
  if (to[key] == null) {
50
55
  to[key] = from[key];
51
56
  } else if (isObject(from[key])) {
@@ -2,6 +2,9 @@
2
2
 
3
3
  const get = require('../get');
4
4
  const utils = require('../../utils');
5
+
6
+ const simpleCollation = Object.freeze({ locale: 'simple' });
7
+
5
8
  /**
6
9
  * Given a Mongoose index definition (key + options objects) and a MongoDB server
7
10
  * index definition, determine if the two indexes are equal.
@@ -62,14 +65,13 @@ module.exports = function isIndexEqual(schemaIndexKeysObject, options, dbIndex)
62
65
  continue;
63
66
  }
64
67
  if (key === 'collation') {
65
- if (options[key] == null || dbIndex[key] == null) {
66
- return options[key] == null && dbIndex[key] == null;
67
- }
68
- const definedKeys = Object.keys(options.collation);
69
- const schemaCollation = options.collation;
70
- const dbCollation = dbIndex.collation;
71
- for (const opt of definedKeys) {
72
- if (get(schemaCollation, opt) !== get(dbCollation, opt)) {
68
+ // No collation is equivalent to { locale: 'simple' }. MongoDB server 9
69
+ // reports { locale: 'simple' } for indexes created with no collation,
70
+ // older versions omit it.
71
+ const schemaCollation = options.collation ?? simpleCollation;
72
+ const dbCollation = dbIndex.collation ?? simpleCollation;
73
+ for (const opt of Object.keys(schemaCollation)) {
74
+ if (schemaCollation[opt] !== dbCollation[opt]) {
73
75
  return false;
74
76
  }
75
77
  }
@@ -209,6 +209,26 @@ const methods = {
209
209
  return this.constructor.prototype.toObject.apply(this, arguments);
210
210
  },
211
211
 
212
+ /**
213
+ * Wraps [`MongooseArray#addToSet`](https://mongoosejs.com/docs/api/array.html#MongooseArray.prototype.addToSet())
214
+ * with proper change tracking.
215
+ *
216
+ * @param {...object} [args]
217
+ * @api public
218
+ * @method addToSet
219
+ * @memberOf MongooseDocumentArray
220
+ */
221
+
222
+ addToSet() {
223
+ // Arguments are cast before duplicates are skipped, so any value added
224
+ // after a skipped duplicate is cast with an index that is too high.
225
+ const ret = ArrayMethods.addToSet.apply(this, arguments);
226
+
227
+ _updateSubdocIndexes(this);
228
+
229
+ return ret;
230
+ },
231
+
212
232
  /**
213
233
  * Wraps [`Array#push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking.
214
234
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.24.3",
4
+ "version": "8.24.5",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",