mongoose 9.10.3 → 9.10.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.
@@ -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.
@@ -61,14 +64,13 @@ module.exports = function isIndexEqual(schemaIndexKeysObject, options, dbIndex)
61
64
  continue;
62
65
  }
63
66
  if (key === 'collation') {
64
- if (options[key] == null || dbIndex[key] == null) {
65
- return options[key] == null && dbIndex[key] == null;
66
- }
67
- const definedKeys = Object.keys(options.collation);
68
- const schemaCollation = options.collation;
69
- const dbCollation = dbIndex.collation;
70
- for (const opt of definedKeys) {
71
- if (get(schemaCollation, opt) !== get(dbCollation, opt)) {
67
+ // No collation is equivalent to { locale: 'simple' }. MongoDB server 9
68
+ // reports { locale: 'simple' } for indexes created with no collation,
69
+ // older versions omit it.
70
+ const schemaCollation = options.collation ?? simpleCollation;
71
+ const dbCollation = dbIndex.collation ?? simpleCollation;
72
+ for (const opt of Object.keys(schemaCollation)) {
73
+ if (schemaCollation[opt] !== dbCollation[opt]) {
72
74
  return false;
73
75
  }
74
76
  }
@@ -97,7 +97,15 @@ function _castExpression(val, schema, strictQuery) {
97
97
  val.$ifNull.map(v => _castExpression(v, schema, strictQuery));
98
98
  } else if (val.$switch != null) {
99
99
  if (Array.isArray(val.$switch.branches)) {
100
- val.$switch.branches = val.$switch.branches.map(v => _castExpression(v, schema, strictQuery));
100
+ for (const branch of val.$switch.branches) {
101
+ if (branch?.case != null) {
102
+ branch.case = _castExpression(branch.case, schema, strictQuery);
103
+ }
104
+ if (branch?.then != null) {
105
+ branch.then = _castExpression(branch.then, schema, strictQuery);
106
+ }
107
+ omitUndefined(branch);
108
+ }
101
109
  }
102
110
  if ('default' in val.$switch) {
103
111
  val.$switch.default = _castExpression(val.$switch.default, schema, strictQuery);
package/lib/model.js CHANGED
@@ -4769,7 +4769,10 @@ async function _populatePath(model, docs, populateOptions) {
4769
4769
  // Get the assigned (filtered) children from parent docs
4770
4770
  const childDocsToPopulate = [];
4771
4771
  for (const doc of mod.docs) {
4772
- const childVal = doc.$__ != null ? doc.get(mod.options.path) : doc[mod.options.path];
4772
+ // `utils.getValue()` rather than a bracket lookup, because `mod.options.path` may be
4773
+ // a dotted path like 'children.child', which a lean result does not store as a
4774
+ // single key.
4775
+ const childVal = doc.$__ != null ? doc.get(mod.options.path) : utils.getValue(mod.options.path, doc);
4773
4776
  if (Array.isArray(childVal)) {
4774
4777
  childDocsToPopulate.push(...childVal);
4775
4778
  } else if (childVal != null) {
@@ -544,11 +544,13 @@ const methods = {
544
544
  if (isBsonType(obj, 'ObjectId')) {
545
545
  obj = obj.toString();
546
546
  }
547
+ // Compare dates by timestamp like `addToSet()` does, so `pull()` works on date arrays
548
+ const isDate = obj instanceof Date;
547
549
 
548
550
  fromIndex = fromIndex == null ? 0 : fromIndex;
549
551
  const len = this.length;
550
552
  for (let i = fromIndex; i < len; ++i) {
551
- if (obj == this[i]) {
553
+ if (obj == this[i] || (isDate && this[i] instanceof Date && +obj === +this[i])) {
552
554
  return i;
553
555
  }
554
556
  }
package/lib/types/map.js CHANGED
@@ -4,6 +4,7 @@ const Mixed = require('../schema/mixed');
4
4
  const MongooseError = require('../error/mongooseError');
5
5
  const clone = require('../helpers/clone');
6
6
  const deepEqual = require('../utils').deepEqual;
7
+ const isMongooseArray = require('../utils').isMongooseArray;
7
8
  const getConstructorName = require('../helpers/getConstructorName');
8
9
  const handleSpreadDoc = require('../helpers/document/handleSpreadDoc');
9
10
  const util = require('util');
@@ -160,6 +161,11 @@ class MongooseMap extends Map {
160
161
  if (parent?.$__ != null && !deepEqual(value, priorVal)) {
161
162
  const path = fullPath.call(this);
162
163
  parent.markModified(path);
164
+ // Replacing the whole array means later push(), pull() or addToSet() calls must not be sent as
165
+ // atomics against the array that was in the database, same as Document#$set re: gh-1126
166
+ if (isMongooseArray(value)) {
167
+ value._registerAtomic('$set', value);
168
+ }
163
169
  // If overwriting the full document array or subdoc, make sure to clean up any paths that were modified
164
170
  // before re: #15108
165
171
  if (this.$__schemaType.$isMongooseDocumentArray || this.$__schemaType.$isSingleNested) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "9.10.3",
4
+ "version": "9.10.4",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -29,9 +29,9 @@
29
29
  "sift": "17.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@ark/attest": "0.56.3",
32
+ "@ark/attest": "0.56.5",
33
33
  "@eslint/js": "^9.39.3",
34
- "@mongodb-js/mongodb-downloader": "^1.0.0",
34
+ "@mongodb-js/mongodb-downloader": "^2.0.2",
35
35
  "@types/node": "^20.19.0",
36
36
  "acquit": "1.4.0",
37
37
  "acquit-ignore": "0.2.2",
@@ -40,7 +40,7 @@
40
40
  "c8": "12.0.0",
41
41
  "cheerio": "1.2.0",
42
42
  "dox": "1.0.0",
43
- "eslint": "10.9.1",
43
+ "eslint": "10.11.0",
44
44
  "eslint-plugin-mocha-no-only": "1.2.0",
45
45
  "express": "5.2.1",
46
46
  "fs-extra": "~11.4.0",
@@ -50,13 +50,13 @@
50
50
  "linkinator": "8.x",
51
51
  "lodash.isequal": "4.5.0",
52
52
  "lodash.isequalwith": "4.4.0",
53
- "markdownlint-cli2": "0.23.2",
54
- "marked": "18.0.11",
53
+ "markdownlint-cli2": "0.23.3",
54
+ "marked": "18.0.14",
55
55
  "mkdirp": "^3.0.1",
56
- "mocha": "12.0.0-rc.6",
57
- "moment": "2.30.1",
56
+ "mocha": "12.0.2",
57
+ "moment": "2.31.0",
58
58
  "mongodb-client-encryption": "^7.2.0",
59
- "mongodb-memory-server": "11.2.0",
59
+ "mongodb-memory-server": "11.3.0",
60
60
  "mongodb-runner": "^6.0.0",
61
61
  "ncp": "^2.0.0",
62
62
  "pug": "3.0.4",