mongoose 8.5.3 → 8.5.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/cast.js CHANGED
@@ -8,6 +8,7 @@ const CastError = require('./error/cast');
8
8
  const StrictModeError = require('./error/strict');
9
9
  const Types = require('./schema/index');
10
10
  const cast$expr = require('./helpers/query/cast$expr');
11
+ const castString = require('./cast/string');
11
12
  const castTextSearch = require('./schema/operators/text');
12
13
  const get = require('./helpers/get');
13
14
  const getSchemaDiscriminatorByValue = require('./helpers/discriminator/getSchemaDiscriminatorByValue');
@@ -95,6 +96,9 @@ module.exports = function cast(schema, obj, options, context) {
95
96
  val = cast(schema, val, options, context);
96
97
  } else if (path === '$text') {
97
98
  val = castTextSearch(val, path);
99
+ } else if (path === '$comment' && !schema.paths.hasOwnProperty('$comment')) {
100
+ val = castString(val, path);
101
+ obj[path] = val;
98
102
  } else {
99
103
  if (!schema) {
100
104
  // no casting for Mixed types
package/lib/model.js CHANGED
@@ -10,6 +10,7 @@ const Document = require('./document');
10
10
  const DocumentNotFoundError = require('./error/notFound');
11
11
  const EventEmitter = require('events').EventEmitter;
12
12
  const Kareem = require('kareem');
13
+ const MongooseBulkWriteError = require('./error/bulkWriteError');
13
14
  const MongooseError = require('./error/index');
14
15
  const ObjectParameterError = require('./error/objectParameter');
15
16
  const OverwriteModelError = require('./error/overwriteModel');
@@ -62,7 +63,6 @@ const setDottedPath = require('./helpers/path/setDottedPath');
62
63
  const STATES = require('./connectionState');
63
64
  const util = require('util');
64
65
  const utils = require('./utils');
65
- const MongooseBulkWriteError = require('./error/bulkWriteError');
66
66
  const minimize = require('./helpers/minimize');
67
67
 
68
68
  const modelCollectionSymbol = Symbol('mongoose#Model#collection');
@@ -3202,8 +3202,8 @@ function _setIsNew(doc, val) {
3202
3202
  * @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
3203
3203
  * @param {Boolean} [options.skipValidation=false] Set to true to skip Mongoose schema validation on bulk write operations. Mongoose currently runs validation on `insertOne` and `replaceOne` operations by default.
3204
3204
  * @param {Boolean} [options.bypassDocumentValidation=false] If true, disable [MongoDB server-side schema validation](https://www.mongodb.com/docs/manual/core/schema-validation/) for all writes in this bulk.
3205
- * @param {Boolean} [options.throwOnValidationError=false] If true and `ordered: false`, throw an error if one of the operations failed validation, but all valid operations completed successfully.
3206
- * @param {Boolean} [options.strict=null] Overwrites the [`strict` option](https://mongoosejs.com/docs/guide.html#strict) on schema. If false, allows filtering and writing fields not defined in the schema for all writes in this bulk.
3205
+ * @param {Boolean} [options.throwOnValidationError=false] If true and `ordered: false`, throw an error if one of the operations failed validation, but all valid operations completed successfully. Note that Mongoose will still send all valid operations to the MongoDB server.
3206
+ * @param {Boolean|"throw"} [options.strict=null] Overwrites the [`strict` option](https://mongoosejs.com/docs/guide.html#strict) on schema. If false, allows filtering and writing fields not defined in the schema for all writes in this bulk.
3207
3207
  * @return {Promise} resolves to a [`BulkWriteOpResult`](https://mongodb.github.io/node-mongodb-native/4.9/classes/BulkWriteResult.html) if the operation succeeds
3208
3208
  * @api public
3209
3209
  */
package/lib/mongoose.js CHANGED
@@ -358,7 +358,7 @@ Mongoose.prototype.get = Mongoose.prototype.set;
358
358
  *
359
359
  * // initialize now, connect later
360
360
  * db = mongoose.createConnection();
361
- * db.openUri('127.0.0.1', 'database', port, [opts]);
361
+ * await db.openUri('mongodb://127.0.0.1:27017/database');
362
362
  *
363
363
  * @param {String} uri mongodb URI to connect to
364
364
  * @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/MongoClientOptions.html), except for 4 mongoose-specific options explained below.
@@ -406,11 +406,10 @@ Mongoose.prototype.createConnection = function(uri, options) {
406
406
  * // with options
407
407
  * mongoose.connect(uri, options);
408
408
  *
409
- * // optional callback that gets fired when initial connection completed
409
+ * // Using `await` throws "MongooseServerSelectionError: Server selection timed out after 30000 ms"
410
+ * // if Mongoose can't connect.
410
411
  * const uri = 'mongodb://nonexistent.domain:27000';
411
- * mongoose.connect(uri, function(error) {
412
- * // if error is truthy, the initial connection failed.
413
- * })
412
+ * await mongoose.connect(uri);
414
413
  *
415
414
  * @param {String} uri mongodb URI to connect to
416
415
  * @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/MongoClientOptions.html), except for 4 mongoose-specific options explained below.
package/lib/query.js CHANGED
@@ -2446,19 +2446,23 @@ Query.prototype.merge = function(source) {
2446
2446
  }
2447
2447
 
2448
2448
  opts.omit = {};
2449
- if (source.$and) {
2449
+ if (Array.isArray(source.$and)) {
2450
2450
  opts.omit['$and'] = true;
2451
2451
  if (!this._conditions) {
2452
2452
  this._conditions = {};
2453
2453
  }
2454
- this._conditions.$and = (this._conditions.$and || []).concat(source.$and);
2454
+ this._conditions.$and = (this._conditions.$and || []).concat(
2455
+ source.$and.map(el => utils.isPOJO(el) ? utils.merge({}, el) : el)
2456
+ );
2455
2457
  }
2456
- if (source.$or) {
2458
+ if (Array.isArray(source.$or)) {
2457
2459
  opts.omit['$or'] = true;
2458
2460
  if (!this._conditions) {
2459
2461
  this._conditions = {};
2460
2462
  }
2461
- this._conditions.$or = (this._conditions.$or || []).concat(source.$or);
2463
+ this._conditions.$or = (this._conditions.$or || []).concat(
2464
+ source.$or.map(el => utils.isPOJO(el) ? utils.merge({}, el) : el)
2465
+ );
2462
2466
  }
2463
2467
 
2464
2468
  // plain object
@@ -15,7 +15,7 @@ const castString = require('../../cast/string');
15
15
  * @api private
16
16
  */
17
17
 
18
- module.exports = function(val, path) {
18
+ module.exports = function castTextSearch(val, path) {
19
19
  if (val == null || typeof val !== 'object') {
20
20
  throw new CastError('$text', val, path);
21
21
  }
package/lib/utils.js CHANGED
@@ -53,6 +53,12 @@ exports.toCollectionName = function(name, pluralize) {
53
53
  return name;
54
54
  }
55
55
  if (typeof pluralize === 'function') {
56
+ if (typeof name !== 'string') {
57
+ throw new TypeError('Collection name must be a string');
58
+ }
59
+ if (name.length === 0) {
60
+ throw new TypeError('Collection name cannot be empty');
61
+ }
56
62
  return pluralize(name);
57
63
  }
58
64
  return name;
@@ -301,6 +307,8 @@ exports.merge = function merge(to, from, options, path) {
301
307
  to[key] = from[key];
302
308
  }
303
309
  }
310
+
311
+ return to;
304
312
  };
305
313
 
306
314
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.5.3",
4
+ "version": "8.5.4",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -53,7 +53,7 @@
53
53
  "lodash.isequal": "4.5.0",
54
54
  "lodash.isequalwith": "4.4.0",
55
55
  "markdownlint-cli2": "^0.13.0",
56
- "marked": "4.3.0",
56
+ "marked": "14.0.0",
57
57
  "mkdirp": "^3.0.1",
58
58
  "mocha": "10.7.0",
59
59
  "moment": "2.30.1",
package/types/query.d.ts CHANGED
@@ -431,7 +431,7 @@ declare module 'mongoose' {
431
431
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
432
432
  findOne(
433
433
  filter?: FilterQuery<RawDocType>
434
- ): QueryWithHelpers<DocType | null, RawDocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
434
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
435
435
 
436
436
  /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
437
437
  findOneAndDelete(