mongoose 8.17.0 → 8.17.1

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.
@@ -14,7 +14,8 @@ const CUSTOMIZABLE_DISCRIMINATOR_OPTIONS = {
14
14
  _id: true,
15
15
  id: true,
16
16
  virtuals: true,
17
- methods: true
17
+ methods: true,
18
+ statics: true
18
19
  };
19
20
 
20
21
  /**
package/lib/model.js CHANGED
@@ -1099,7 +1099,7 @@ Model.init = function init() {
1099
1099
  return;
1100
1100
  }
1101
1101
 
1102
- return await this.ensureSearchIndexes();
1102
+ return await this.createSearchIndexes();
1103
1103
  };
1104
1104
  const _createCollection = async() => {
1105
1105
  let autoCreate = utils.getOption(
@@ -2092,9 +2092,7 @@ Model.find = function find(conditions, projection, options) {
2092
2092
  };
2093
2093
 
2094
2094
  /**
2095
- * Finds a single document by its _id field. `findById(id)` is almost*
2096
- * equivalent to `findOne({ _id: id })`. If you want to query by a document's
2097
- * `_id`, use `findById()` instead of `findOne()`.
2095
+ * Finds a single document by its _id field. `findById(id)` is equivalent to `findOne({ _id: id })`.
2098
2096
  *
2099
2097
  * The `id` is cast based on the Schema before sending the command.
2100
2098
  *
@@ -2102,11 +2100,6 @@ Model.find = function find(conditions, projection, options) {
2102
2100
  *
2103
2101
  * - `findOne()`
2104
2102
  *
2105
- * \* Except for how it treats `undefined`. If you use `findOne()`, you'll see
2106
- * that `findOne(undefined)` and `findOne({ _id: undefined })` are equivalent
2107
- * to `findOne({})` and return arbitrary documents. However, mongoose
2108
- * translates `findById(undefined)` into `findOne({ _id: null })`.
2109
- *
2110
2103
  * #### Example:
2111
2104
  *
2112
2105
  * // Find the adventure with the given `id`, or `null` if not found
@@ -2131,10 +2124,6 @@ Model.findById = function findById(id, projection, options) {
2131
2124
  throw new MongooseError('Model.findById() no longer accepts a callback');
2132
2125
  }
2133
2126
 
2134
- if (typeof id === 'undefined') {
2135
- id = null;
2136
- }
2137
-
2138
2127
  return this.findOne({ _id: id }, projection, options);
2139
2128
  };
2140
2129
 
package/lib/query.js CHANGED
@@ -2133,6 +2133,29 @@ Query.prototype._optionsForExec = function(model) {
2133
2133
  }
2134
2134
  }
2135
2135
 
2136
+ if (this._mongooseOptions.populate) {
2137
+ if (options.readPreference) {
2138
+ for (const pop of Object.values(this._mongooseOptions.populate)) {
2139
+ if (pop.options?.readPreference === undefined) {
2140
+ if (!pop.options) {
2141
+ pop.options = {};
2142
+ }
2143
+ pop.options.readPreference = options.readPreference;
2144
+ }
2145
+ }
2146
+ }
2147
+ if (options.readConcern) {
2148
+ for (const pop of Object.values(this._mongooseOptions.populate)) {
2149
+ if (pop.options?.readConcern === undefined) {
2150
+ if (!pop.options) {
2151
+ pop.options = {};
2152
+ }
2153
+ pop.options.readConcern = options.readConcern;
2154
+ }
2155
+ }
2156
+ }
2157
+ }
2158
+
2136
2159
  return options;
2137
2160
  };
2138
2161
 
@@ -4918,24 +4941,6 @@ Query.prototype.populate = function() {
4918
4941
 
4919
4942
  const res = utils.populate.apply(null, args);
4920
4943
 
4921
- // Propagate readConcern and readPreference and lean from parent query,
4922
- // unless one already specified
4923
- if (this.options != null) {
4924
- const readConcern = this.options.readConcern;
4925
- const readPref = this.options.readPreference;
4926
-
4927
- for (const populateOptions of res) {
4928
- if (readConcern != null && (populateOptions && populateOptions.options && populateOptions.options.readConcern) == null) {
4929
- populateOptions.options = populateOptions.options || {};
4930
- populateOptions.options.readConcern = readConcern;
4931
- }
4932
- if (readPref != null && (populateOptions && populateOptions.options && populateOptions.options.readPreference) == null) {
4933
- populateOptions.options = populateOptions.options || {};
4934
- populateOptions.options.readPreference = readPref;
4935
- }
4936
- }
4937
- }
4938
-
4939
4944
  const opts = this._mongooseOptions;
4940
4945
 
4941
4946
  if (opts.lean != null) {
@@ -381,7 +381,7 @@ SchemaString.prototype.trim = function(shouldTrim) {
381
381
  *
382
382
  * #### Example:
383
383
  *
384
- * const schema = new Schema({ postalCode: { type: String, minlength: 5 })
384
+ * const schema = new Schema({ postalCode: { type: String, minLength: 5 })
385
385
  * const Address = db.model('Address', schema)
386
386
  * const address = new Address({ postalCode: '9512' })
387
387
  * address.save(function (err) {
@@ -392,8 +392,8 @@ SchemaString.prototype.trim = function(shouldTrim) {
392
392
  *
393
393
  * // custom error messages
394
394
  * // We can also use the special {MINLENGTH} token which will be replaced with the minimum allowed length
395
- * const minlength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
396
- * const schema = new Schema({ postalCode: { type: String, minlength: minlength })
395
+ * const minLength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
396
+ * const schema = new Schema({ postalCode: { type: String, minLength: minLength })
397
397
  * const Address = mongoose.model('Address', schema);
398
398
  * const address = new Address({ postalCode: '9512' });
399
399
  * address.validate(function (err) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.17.0",
4
+ "version": "8.17.1",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -29,8 +29,8 @@
29
29
  "sift": "17.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@babel/core": "7.27.7",
33
- "@babel/preset-env": "7.27.2",
32
+ "@babel/core": "7.28.0",
33
+ "@babel/preset-env": "7.28.0",
34
34
  "@mongodb-js/mongodb-downloader": "^0.4.2",
35
35
  "@typescript-eslint/eslint-plugin": "^8.19.1",
36
36
  "@typescript-eslint/parser": "^8.19.1",
@@ -42,7 +42,7 @@
42
42
  "babel-loader": "8.2.5",
43
43
  "broken-link-checker": "^0.7.8",
44
44
  "buffer": "^5.6.0",
45
- "cheerio": "1.1.0",
45
+ "cheerio": "1.1.2",
46
46
  "crypto-browserify": "3.12.1",
47
47
  "dox": "1.0.0",
48
48
  "eslint": "8.57.1",
@@ -69,7 +69,7 @@
69
69
  "tsd": "0.32.0",
70
70
  "typescript": "5.8.3",
71
71
  "uuid": "11.1.0",
72
- "webpack": "5.99.9"
72
+ "webpack": "5.101.0"
73
73
  },
74
74
  "directories": {
75
75
  "lib": "./lib/mongoose"
package/types/index.d.ts CHANGED
@@ -704,9 +704,9 @@ declare module 'mongoose' {
704
704
  [K in keyof T]?: T[K] extends Record<string, any> ? Projector<T[K], Element> | Element : Element;
705
705
  }
706
706
  : Element;
707
- type _IDType = { _id?: boolean | 1 | 0 };
707
+ type _IDType = { _id?: boolean | number };
708
708
  export type InclusionProjection<T> = IsItRecordAndNotAny<T> extends true
709
- ? Omit<Projector<WithLevel1NestedPaths<T>, true | 1>, '_id'> & _IDType
709
+ ? Omit<Projector<WithLevel1NestedPaths<T>, boolean | number>, '_id'> & _IDType
710
710
  : AnyObject;
711
711
  export type ExclusionProjection<T> = IsItRecordAndNotAny<T> extends true
712
712
  ? Omit<Projector<WithLevel1NestedPaths<T>, false | 0>, '_id'> & _IDType
@@ -207,9 +207,11 @@ declare module 'mongoose' {
207
207
 
208
208
  /** If set, Mongoose will add a custom validator that ensures the given string's `length` is at least the given number. */
209
209
  minlength?: number | [number, string] | readonly [number, string];
210
+ minLength?: number | [number, string] | readonly [number, string];
210
211
 
211
212
  /** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
212
213
  maxlength?: number | [number, string] | readonly [number, string];
214
+ maxLength?: number | [number, string] | readonly [number, string];
213
215
 
214
216
  [other: string]: any;
215
217