mongoose 6.9.0 → 6.9.2

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/aggregate.js CHANGED
@@ -42,7 +42,7 @@ const validRedactStringValues = new Set(['$$DESCEND', '$$PRUNE', '$$KEEP']);
42
42
  * // Do this instead to cast to an ObjectId
43
43
  * new Aggregate([{ $match: { _id: new mongoose.Types.ObjectId('00000000000000000000000a') } }]);
44
44
  *
45
- * @see MongoDB https://docs.mongodb.org/manual/applications/aggregation/
45
+ * @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
46
46
  * @see driver https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#aggregate
47
47
  * @param {Array} [pipeline] aggregation pipeline as an array of objects
48
48
  * @param {Model} [model] the model to use with this aggregate.
@@ -60,23 +60,23 @@ function Aggregate(pipeline, model) {
60
60
  }
61
61
 
62
62
  /**
63
- * Contains options passed down to the [aggregate command](https://docs.mongodb.com/manual/reference/command/aggregate/).
63
+ * Contains options passed down to the [aggregate command](https://www.mongodb.com/docs/manual/reference/command/aggregate/).
64
64
  * Supported options are:
65
65
  *
66
- * - [`allowDiskUse`](./api/aggregate.html#aggregate_Aggregate-allowDiskUse)
66
+ * - [`allowDiskUse`](#aggregate_Aggregate-allowDiskUse)
67
67
  * - `bypassDocumentValidation`
68
- * - [`collation`](./api/aggregate.html#aggregate_Aggregate-collation)
68
+ * - [`collation`](#aggregate_Aggregate-collation)
69
69
  * - `comment`
70
- * - [`cursor`](./api/aggregate.html#aggregate_Aggregate-cursor)
71
- * - [`explain`](./api/aggregate.html#aggregate_Aggregate-explain)
70
+ * - [`cursor`](#aggregate_Aggregate-cursor)
71
+ * - [`explain`](#aggregate_Aggregate-explain)
72
72
  * - `fieldsAsRaw`
73
- * - `hint`
73
+ * - [`hint`](#aggregate_Aggregate-hint)
74
74
  * - `let`
75
75
  * - `maxTimeMS`
76
76
  * - `raw`
77
- * - `readConcern`
77
+ * - [`readConcern`](#aggregate_Aggregate-readConcern)
78
78
  * - `readPreference`
79
- * - [`session`](./api/aggregate.html#aggregate_Aggregate-session)
79
+ * - [`session`](#aggregate_Aggregate-session)
80
80
  * - `writeConcern`
81
81
  *
82
82
  * @property options
@@ -172,7 +172,7 @@ Aggregate.prototype.append = function() {
172
172
  * aggregate.addFields({ salary_k: { $divide: [ "$salary", 1000 ] } });
173
173
  *
174
174
  * @param {Object} arg field specification
175
- * @see $addFields https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/
175
+ * @see $addFields https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/
176
176
  * @return {Aggregate}
177
177
  * @api public
178
178
  */
@@ -210,7 +210,7 @@ Aggregate.prototype.addFields = function(arg) {
210
210
  * aggregate.project({ salary_k: { $divide: [ "$salary", 1000 ] } });
211
211
  *
212
212
  * @param {Object|String} arg field specification
213
- * @see projection https://docs.mongodb.org/manual/reference/aggregation/project/
213
+ * @see projection https://www.mongodb.com/docs/manual/reference/aggregation/project/
214
214
  * @return {Aggregate}
215
215
  * @api public
216
216
  */
@@ -247,7 +247,7 @@ Aggregate.prototype.project = function(arg) {
247
247
  *
248
248
  * aggregate.group({ _id: "$department" });
249
249
  *
250
- * @see $group https://docs.mongodb.org/manual/reference/aggregation/group/
250
+ * @see $group https://www.mongodb.com/docs/manual/reference/aggregation/group/
251
251
  * @method group
252
252
  * @memberOf Aggregate
253
253
  * @instance
@@ -263,7 +263,7 @@ Aggregate.prototype.project = function(arg) {
263
263
  *
264
264
  * aggregate.match({ department: { $in: [ "sales", "engineering" ] } });
265
265
  *
266
- * @see $match https://docs.mongodb.org/manual/reference/aggregation/match/
266
+ * @see $match https://www.mongodb.com/docs/manual/reference/aggregation/match/
267
267
  * @method match
268
268
  * @memberOf Aggregate
269
269
  * @instance
@@ -279,7 +279,7 @@ Aggregate.prototype.project = function(arg) {
279
279
  *
280
280
  * aggregate.skip(10);
281
281
  *
282
- * @see $skip https://docs.mongodb.org/manual/reference/aggregation/skip/
282
+ * @see $skip https://www.mongodb.com/docs/manual/reference/aggregation/skip/
283
283
  * @method skip
284
284
  * @memberOf Aggregate
285
285
  * @instance
@@ -295,7 +295,7 @@ Aggregate.prototype.project = function(arg) {
295
295
  *
296
296
  * aggregate.limit(10);
297
297
  *
298
- * @see $limit https://docs.mongodb.org/manual/reference/aggregation/limit/
298
+ * @see $limit https://www.mongodb.com/docs/manual/reference/aggregation/limit/
299
299
  * @method limit
300
300
  * @memberOf Aggregate
301
301
  * @instance
@@ -360,16 +360,15 @@ Aggregate.prototype.project = function(arg) {
360
360
  * #### Example:
361
361
  *
362
362
  * aggregate.near({
363
- * near: [40.724, -73.997],
363
+ * near: { type: 'Point', coordinates: [40.724, -73.997] },
364
364
  * distanceField: "dist.calculated", // required
365
365
  * maxDistance: 0.008,
366
366
  * query: { type: "public" },
367
367
  * includeLocs: "dist.location",
368
- * uniqueDocs: true,
369
- * num: 5
368
+ * spherical: true,
370
369
  * });
371
370
  *
372
- * @see $geoNear https://docs.mongodb.org/manual/reference/aggregation/geoNear/
371
+ * @see $geoNear https://www.mongodb.com/docs/manual/reference/aggregation/geoNear/
373
372
  * @method near
374
373
  * @memberOf Aggregate
375
374
  * @instance
@@ -408,8 +407,8 @@ Aggregate.prototype.near = function(arg) {
408
407
  * aggregate.unwind("a", "b", "c");
409
408
  * aggregate.unwind({ path: '$tags', preserveNullAndEmptyArrays: true });
410
409
  *
411
- * @see $unwind https://docs.mongodb.org/manual/reference/aggregation/unwind/
412
- * @param {String|Object|String[]|Object[]} fields the field(s) to unwind, either as field names or as [objects with options](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/#document-operand-with-options). If passing a string, prefixing the field name with '$' is optional. If passing an object, `path` must start with '$'.
410
+ * @see $unwind https://www.mongodb.com/docs/manual/reference/aggregation/unwind/
411
+ * @param {String|Object|String[]|Object[]} fields the field(s) to unwind, either as field names or as [objects with options](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#document-operand-with-options). If passing a string, prefixing the field name with '$' is optional. If passing an object, `path` must start with '$'.
413
412
  * @return {Aggregate}
414
413
  * @api public
415
414
  */
@@ -447,7 +446,7 @@ Aggregate.prototype.unwind = function() {
447
446
  *
448
447
  * aggregate.replaceRoot({ x: { $concat: ['$this', '$that'] } });
449
448
  *
450
- * @see $replaceRoot https://docs.mongodb.org/manual/reference/operator/aggregation/replaceRoot
449
+ * @see $replaceRoot https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot
451
450
  * @param {String|Object} newRoot the field or document which will become the new root document
452
451
  * @return {Aggregate}
453
452
  * @api public
@@ -476,7 +475,7 @@ Aggregate.prototype.replaceRoot = function(newRoot) {
476
475
  *
477
476
  * aggregate.count("userCount");
478
477
  *
479
- * @see $count https://docs.mongodb.org/manual/reference/operator/aggregation/count
478
+ * @see $count https://www.mongodb.com/docs/manual/reference/operator/aggregation/count
480
479
  * @param {String} fieldName The name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character.
481
480
  * @return {Aggregate}
482
481
  * @api public
@@ -498,7 +497,7 @@ Aggregate.prototype.count = function(fieldName) {
498
497
  * aggregate.sortByCount('users');
499
498
  * aggregate.sortByCount({ $mergeObjects: [ "$employee", "$business" ] })
500
499
  *
501
- * @see $sortByCount https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/
500
+ * @see $sortByCount https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/
502
501
  * @param {Object|String} arg
503
502
  * @return {Aggregate} this
504
503
  * @api public
@@ -524,7 +523,7 @@ Aggregate.prototype.sortByCount = function(arg) {
524
523
  *
525
524
  * aggregate.lookup({ from: 'users', localField: 'userId', foreignField: '_id', as: 'users' });
526
525
  *
527
- * @see $lookup https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/#pipe._S_lookup
526
+ * @see $lookup https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#pipe._S_lookup
528
527
  * @param {Object} options to $lookup as described in the above link
529
528
  * @return {Aggregate}
530
529
  * @api public
@@ -544,7 +543,7 @@ Aggregate.prototype.lookup = function(options) {
544
543
  * // Suppose we have a collection of courses, where a document might look like `{ _id: 0, name: 'Calculus', prerequisite: 'Trigonometry'}` and `{ _id: 0, name: 'Trigonometry', prerequisite: 'Algebra' }`
545
544
  * aggregate.graphLookup({ from: 'courses', startWith: '$prerequisite', connectFromField: 'prerequisite', connectToField: 'name', as: 'prerequisites', maxDepth: 3 }) // this will recursively search the 'courses' collection up to 3 prerequisites
546
545
  *
547
- * @see $graphLookup https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/#pipe._S_graphLookup
546
+ * @see $graphLookup https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#pipe._S_graphLookup
548
547
  * @param {Object} options to $graphLookup as described in the above link
549
548
  * @return {Aggregate}
550
549
  * @api public
@@ -577,7 +576,7 @@ Aggregate.prototype.graphLookup = function(options) {
577
576
  *
578
577
  * aggregate.sample(3); // Add a pipeline that picks 3 random documents
579
578
  *
580
- * @see $sample https://docs.mongodb.org/manual/reference/operator/aggregation/sample/#pipe._S_sample
579
+ * @see $sample https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#pipe._S_sample
581
580
  * @param {Number} size number of random documents to pick
582
581
  * @return {Aggregate}
583
582
  * @api public
@@ -600,7 +599,7 @@ Aggregate.prototype.sample = function(size) {
600
599
  * aggregate.sort({ field: 'asc', test: -1 });
601
600
  * aggregate.sort('field -test');
602
601
  *
603
- * @see $sort https://docs.mongodb.org/manual/reference/aggregation/sort/
602
+ * @see $sort https://www.mongodb.com/docs/manual/reference/aggregation/sort/
604
603
  * @param {Object|String} arg
605
604
  * @return {Aggregate} this
606
605
  * @api public
@@ -646,7 +645,7 @@ Aggregate.prototype.sort = function(arg) {
646
645
  *
647
646
  * aggregate.unionWith({ coll: 'users', pipeline: [ { $match: { _id: 1 } } ] });
648
647
  *
649
- * @see $unionWith https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith
648
+ * @see $unionWith https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith
650
649
  * @param {Object} options to $unionWith query as described in the above link
651
650
  * @return {Aggregate}
652
651
  * @api public
@@ -668,7 +667,7 @@ Aggregate.prototype.unionWith = function(options) {
668
667
  * @param {Array} [tags] optional tags for this query. DEPRECATED
669
668
  * @return {Aggregate} this
670
669
  * @api public
671
- * @see mongodb https://docs.mongodb.org/manual/applications/replication/#read-preference
670
+ * @see mongodb https://www.mongodb.com/docs/manual/applications/replication/#read-preference
672
671
  */
673
672
 
674
673
  Aggregate.prototype.read = function(pref, tags) {
@@ -684,7 +683,7 @@ Aggregate.prototype.read = function(pref, tags) {
684
683
  * await Model.aggregate(pipeline).readConcern('majority');
685
684
  *
686
685
  * @param {String} level one of the listed read concern level or their aliases
687
- * @see mongodb https://docs.mongodb.com/manual/reference/read-concern/
686
+ * @see mongodb https://www.mongodb.com/docs/manual/reference/read-concern/
688
687
  * @return {Aggregate} this
689
688
  * @api public
690
689
  */
@@ -717,7 +716,7 @@ Aggregate.prototype.readConcern = function(level) {
717
716
  * @param {String|Object} [thenExpr] true case for the condition
718
717
  * @param {String|Object} [elseExpr] false case for the condition
719
718
  * @return {Aggregate} this
720
- * @see $redact https://docs.mongodb.com/manual/reference/operator/aggregation/redact/
719
+ * @see $redact https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/
721
720
  * @api public
722
721
  */
723
722
 
@@ -819,7 +818,7 @@ Aggregate.prototype.explain = function(verbosity, callback) {
819
818
  *
820
819
  * @param {Boolean} value Should tell server it can use hard drive to store data during aggregation.
821
820
  * @return {Aggregate} this
822
- * @see mongodb https://docs.mongodb.org/manual/reference/command/aggregate/
821
+ * @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
823
822
  */
824
823
 
825
824
  Aggregate.prototype.allowDiskUse = function(value) {
@@ -836,7 +835,7 @@ Aggregate.prototype.allowDiskUse = function(value) {
836
835
  *
837
836
  * @param {Object|String} value a hint object or the index name
838
837
  * @return {Aggregate} this
839
- * @see mongodb https://docs.mongodb.org/manual/reference/command/aggregate/
838
+ * @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
840
839
  */
841
840
 
842
841
  Aggregate.prototype.hint = function(value) {
@@ -854,7 +853,7 @@ Aggregate.prototype.hint = function(value) {
854
853
  *
855
854
  * @param {ClientSession} session
856
855
  * @return {Aggregate} this
857
- * @see mongodb https://docs.mongodb.org/manual/reference/command/aggregate/
856
+ * @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
858
857
  */
859
858
 
860
859
  Aggregate.prototype.session = function(session) {
@@ -875,11 +874,11 @@ Aggregate.prototype.session = function(session) {
875
874
  * agg.options; // `{ allowDiskUse: true }`
876
875
  *
877
876
  * @param {Object} options keys to merge into current options
878
- * @param {Number} [options.maxTimeMS] number limits the time this aggregation will run, see [MongoDB docs on `maxTimeMS`](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/)
877
+ * @param {Number} [options.maxTimeMS] number limits the time this aggregation will run, see [MongoDB docs on `maxTimeMS`](https://www.mongodb.com/docs/manual/reference/operator/meta/maxTimeMS/)
879
878
  * @param {Boolean} [options.allowDiskUse] boolean if true, the MongoDB server will use the hard drive to store data during this aggregation
880
- * @param {Object} [options.collation] object see [`Aggregate.prototype.collation()`](./docs/api/aggregate.html#aggregate_Aggregate-collation)
881
- * @param {ClientSession} [options.session] ClientSession see [`Aggregate.prototype.session()`](./docs/api/aggregate.html#aggregate_Aggregate-session)
882
- * @see mongodb https://docs.mongodb.org/manual/reference/command/aggregate/
879
+ * @param {Object} [options.collation] object see [`Aggregate.prototype.collation()`](#aggregate_Aggregate-collation)
880
+ * @param {ClientSession} [options.session] ClientSession see [`Aggregate.prototype.session()`](#aggregate_Aggregate-session)
881
+ * @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
883
882
  * @return {Aggregate} this
884
883
  * @api public
885
884
  */
@@ -948,7 +947,7 @@ Aggregate.prototype.collation = function(collation) {
948
947
  *
949
948
  * @param {Object} facet options
950
949
  * @return {Aggregate} this
951
- * @see $facet https://docs.mongodb.com/v3.4/reference/operator/aggregation/facet/
950
+ * @see $facet https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/
952
951
  * @api public
953
952
  */
954
953
 
@@ -957,7 +956,7 @@ Aggregate.prototype.facet = function(options) {
957
956
  };
958
957
 
959
958
  /**
960
- * Helper for [Atlas Text Search](https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/)'s
959
+ * Helper for [Atlas Text Search](https://www.mongodb.com/docs/atlas/atlas-search/tutorial/)'s
961
960
  * `$search` stage.
962
961
  *
963
962
  * #### Example:
@@ -974,7 +973,7 @@ Aggregate.prototype.facet = function(options) {
974
973
  *
975
974
  * @param {Object} $search options
976
975
  * @return {Aggregate} this
977
- * @see $search https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/
976
+ * @see $search https://www.mongodb.com/docs/atlas/atlas-search/tutorial/
978
977
  * @api public
979
978
  */
980
979
 
package/lib/connection.js CHANGED
@@ -72,7 +72,7 @@ function Connection(base) {
72
72
  if (typeof base === 'undefined' || !base.connections.length) {
73
73
  this.id = 0;
74
74
  } else {
75
- this.id = base.connections.length;
75
+ this.id = base.nextConnectionId;
76
76
  }
77
77
  this._queue = [];
78
78
  }
@@ -385,8 +385,8 @@ Connection.prototype.config;
385
385
 
386
386
  /**
387
387
  * Helper for `createCollection()`. Will explicitly create the given collection
388
- * with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
389
- * and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
388
+ * with specified options. Used to create [capped collections](https://www.mongodb.com/docs/manual/core/capped-collections/)
389
+ * and [views](https://www.mongodb.com/docs/manual/core/views/) from mongoose.
390
390
  *
391
391
  * Options are passed down without modification to the [MongoDB driver's `createCollection()` function](https://mongodb.github.io/node-mongodb-native/4.9/classes/Db.html#createCollection)
392
392
  *
@@ -407,8 +407,8 @@ Connection.prototype.createCollection = _wrapConnHelper(function createCollectio
407
407
  });
408
408
 
409
409
  /**
410
- * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
411
- * for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
410
+ * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
411
+ * for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
412
412
  * and [transactions](https://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
413
413
  *
414
414
  * #### Example:
@@ -1118,7 +1118,7 @@ Connection.prototype.collection = function(name, options) {
1118
1118
  * @param {Function} fn plugin callback
1119
1119
  * @param {Object} [opts] optional options
1120
1120
  * @return {Connection} this
1121
- * @see plugins /docs/plugins
1121
+ * @see plugins /docs/plugins.html
1122
1122
  * @api public
1123
1123
  */
1124
1124
 
@@ -26,7 +26,7 @@ const util = require('util');
26
26
  * Use [`Aggregate#cursor()`](/docs/api/aggregate.html#aggregate_Aggregate-cursor) instead.
27
27
  *
28
28
  * @param {Aggregate} agg
29
- * @inherits Readable
29
+ * @inherits Readable https://nodejs.org/api/stream.html#class-streamreadable
30
30
  * @event `cursor`: Emitted when the cursor is created
31
31
  * @event `error`: Emitted when an error occurred
32
32
  * @event `data`: Emitted when the stream is flowing and the next doc is ready
@@ -25,7 +25,7 @@ const util = require('util');
25
25
  *
26
26
  * @param {Query} query
27
27
  * @param {Object} options query options passed to `.find()`
28
- * @inherits Readable
28
+ * @inherits Readable https://nodejs.org/api/stream.html#class-streamreadable
29
29
  * @event `cursor`: Emitted when the cursor is created
30
30
  * @event `error`: Emitted when an error occurred
31
31
  * @event `data`: Emitted when the stream is flowing and the next doc is ready
package/lib/document.js CHANGED
@@ -1621,7 +1621,7 @@ Document.prototype.$__shouldModify = function(pathToMark, path, options, constru
1621
1621
  return false;
1622
1622
  }
1623
1623
 
1624
- if (!deepEqual(val, priorVal || utils.getValue(path, this))) {
1624
+ if (!deepEqual(val, priorVal !== undefined ? priorVal : utils.getValue(path, this))) {
1625
1625
  return true;
1626
1626
  }
1627
1627
 
@@ -3211,8 +3211,8 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
3211
3211
  }
3212
3212
 
3213
3213
  /**
3214
- * Saves this document by inserting a new document into the database if [document.isNew](/docs/api/document.html#document_Document-isNew) is `true`,
3215
- * or sends an [updateOne](/docs/api/document.html#document_Document-updateOne) operation **only** with the modifications to the database, it does not replace the whole document in the latter case.
3214
+ * Saves this document by inserting a new document into the database if [document.isNew](#document_Document-isNew) is `true`,
3215
+ * or sends an [updateOne](#document_Document-updateOne) operation **only** with the modifications to the database, it does not replace the whole document in the latter case.
3216
3216
  *
3217
3217
  * #### Example:
3218
3218
  *
@@ -3228,20 +3228,20 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
3228
3228
  * newProduct === product; // true
3229
3229
  *
3230
3230
  * @param {Object} [options] options optional options
3231
- * @param {Session} [options.session=null] the [session](https://docs.mongodb.com/manual/reference/server-sessions/) associated with this save operation. If not specified, defaults to the [document's associated session](api/document.html#document_Document-$session).
3231
+ * @param {Session} [options.session=null] the [session](https://www.mongodb.com/docs/manual/reference/server-sessions/) associated with this save operation. If not specified, defaults to the [document's associated session](#document_Document-$session).
3232
3232
  * @param {Object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com//docs/guide.html#safe). Use the `w` option instead.
3233
3233
  * @param {Boolean} [options.validateBeforeSave] set to false to save without validating.
3234
3234
  * @param {Boolean} [options.validateModifiedOnly=false] If `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
3235
- * @param {Number|String} [options.w] set the [write concern](https://docs.mongodb.com/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
3236
- * @param {Boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://docs.mongodb.com/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
3237
- * @param {Number} [options.wtimeout] sets a [timeout for the write concern](https://docs.mongodb.com/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern).
3238
- * @param {Boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names)
3239
- * @param {Boolean} [options.timestamps=true] if `false` and [timestamps](./guide.html#timestamps) are enabled, skip timestamps for this `save()`.
3235
+ * @param {Number|String} [options.w] set the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
3236
+ * @param {Boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
3237
+ * @param {Number} [options.wtimeout] sets a [timeout for the write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern).
3238
+ * @param {Boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://www.mongodb.com/docs/manual/reference/limits/#Restrictions-on-Field-Names)
3239
+ * @param {Boolean} [options.timestamps=true] if `false` and [timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
3240
3240
  * @param {Function} [fn] optional callback
3241
3241
  * @method save
3242
3242
  * @memberOf Document
3243
3243
  * @instance
3244
- * @throws {DocumentNotFoundError} if this [save updates an existing document](api/document.html#document_Document-isNew) but the document doesn't exist in the database. For example, you will get this error if the document is [deleted between when you retrieved the document and when you saved it](documents.html#updating).
3244
+ * @throws {DocumentNotFoundError} if this [save updates an existing document](#document_Document-isNew) but the document doesn't exist in the database. For example, you will get this error if the document is [deleted between when you retrieved the document and when you saved it](documents.html#updating).
3245
3245
  * @return {Promise|undefined} Returns undefined if used with callback or a Promise otherwise.
3246
3246
  * @api public
3247
3247
  * @see middleware https://mongoosejs.com/docs/middleware.html
@@ -4322,11 +4322,11 @@ Document.prototype.equals = function(doc) {
4322
4322
  * @param {boolean} [options.retainNullValues=false] by default, Mongoose removes null and undefined values from populated arrays. Use this option to make `populate()` retain `null` and `undefined` array entries.
4323
4323
  * @param {boolean} [options.getters=false] if true, Mongoose will call any getters defined on the `localField`. By default, Mongoose gets the raw value of `localField`. For example, you would need to set this option to `true` if you wanted to [add a `lowercase` getter to your `localField`](/docs/schematypes.html#schematype-options).
4324
4324
  * @param {boolean} [options.clone=false] When you do `BlogPost.find().populate('author')`, blog posts with the same author will share 1 copy of an `author` doc. Enable this option to make Mongoose clone populated docs before assigning them.
4325
- * @param {Object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://docs.mongodb.com/manual/tutorial/query-documents/), or a function that returns a filter object.
4325
+ * @param {Object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://www.mongodb.com/docs/manual/tutorial/query-documents/), or a function that returns a filter object.
4326
4326
  * @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
4327
4327
  * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
4328
4328
  * @param {Function} [callback] Callback
4329
- * @see population /docs/populate
4329
+ * @see population /docs/populate.html
4330
4330
  * @see Query#select #query_Query-select
4331
4331
  * @see Model.populate #model_Model-populate
4332
4332
  * @memberOf Document
@@ -17,7 +17,7 @@ const util = require('util');
17
17
  *
18
18
  * All methods methods from the [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) driver are copied and wrapped in queue management.
19
19
  *
20
- * @inherits Collection
20
+ * @inherits Collection https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html
21
21
  * @api private
22
22
  */
23
23
 
@@ -25,19 +25,19 @@ const MongooseError = require('./mongooseError');
25
25
  *
26
26
  * - `MongooseError`: general Mongoose error
27
27
  * - `CastError`: Mongoose could not convert a value to the type defined in the schema path. May be in a `ValidationError` class' `errors` property.
28
- * - `DisconnectedError`: This [connection](connections.html) timed out in trying to reconnect to MongoDB and will not successfully reconnect to MongoDB unless you explicitly reconnect.
28
+ * - `DisconnectedError`: This [connection](/docs/connections.html) timed out in trying to reconnect to MongoDB and will not successfully reconnect to MongoDB unless you explicitly reconnect.
29
29
  * - `DivergentArrayError`: You attempted to `save()` an array that was modified after you loaded it with a `$elemMatch` or similar projection
30
- * - `MissingSchemaError`: You tried to access a model with [`mongoose.model()`](api/mongoose.html#mongoose_Mongoose-model) that was not defined
31
- * - `DocumentNotFoundError`: The document you tried to [`save()`](api/document.html#document_Document-save) was not found
30
+ * - `MissingSchemaError`: You tried to access a model with [`mongoose.model()`](mongoose.html#mongoose_Mongoose-model) that was not defined
31
+ * - `DocumentNotFoundError`: The document you tried to [`save()`](document.html#document_Document-save) was not found
32
32
  * - `ValidatorError`: error from an individual schema path's validator
33
- * - `ValidationError`: error returned from [`validate()`](api/document.html#document_Document-validate) or [`validateSync()`](api/document.html#document_Document-validateSync). Contains zero or more `ValidatorError` instances in `.errors` property.
33
+ * - `ValidationError`: error returned from [`validate()`](document.html#document_Document-validate) or [`validateSync()`](document.html#document_Document-validateSync). Contains zero or more `ValidatorError` instances in `.errors` property.
34
34
  * - `MissingSchemaError`: You called `mongoose.Document()` without a schema
35
- * - `ObjectExpectedError`: Thrown when you set a nested path to a non-object value with [strict mode set](guide.html#strict).
35
+ * - `ObjectExpectedError`: Thrown when you set a nested path to a non-object value with [strict mode set](/docs/guide.html#strict).
36
36
  * - `ObjectParameterError`: Thrown when you pass a non-object value to a function which expects an object as a paramter
37
- * - `OverwriteModelError`: Thrown when you call [`mongoose.model()`](api/mongoose.html#mongoose_Mongoose-model) to re-define a model that was already defined.
38
- * - `ParallelSaveError`: Thrown when you call [`save()`](api/model.html#model_Model-save) on a document when the same document instance is already saving.
39
- * - `StrictModeError`: Thrown when you set a path that isn't the schema and [strict mode](guide.html#strict) is set to `throw`.
40
- * - `VersionError`: Thrown when the [document is out of sync](guide.html#versionKey)
37
+ * - `OverwriteModelError`: Thrown when you call [`mongoose.model()`](mongoose.html#mongoose_Mongoose-model) to re-define a model that was already defined.
38
+ * - `ParallelSaveError`: Thrown when you call [`save()`](model.html#model_Model-save) on a document when the same document instance is already saving.
39
+ * - `StrictModeError`: Thrown when you set a path that isn't the schema and [strict mode](/docs/guide.html#strict) is set to `throw`.
40
+ * - `VersionError`: Thrown when the [document is out of sync](/docs/guide.html#versionKey)
41
41
  *
42
42
  * @api public
43
43
  * @property {String} name
@@ -205,7 +205,7 @@ MongooseError.MongooseServerSelectionError = require('./serverSelection');
205
205
  MongooseError.DivergentArrayError = require('./divergentArray');
206
206
 
207
207
  /**
208
- * Thrown when your try to pass values to model contrtuctor that
208
+ * Thrown when your try to pass values to model constructor that
209
209
  * were not specified in schema or change immutable properties when
210
210
  * `strict` mode is `"throw"`
211
211
  *
@@ -215,3 +215,14 @@ MongooseError.DivergentArrayError = require('./divergentArray');
215
215
  */
216
216
 
217
217
  MongooseError.StrictModeError = require('./strict');
218
+
219
+ /**
220
+ * An instance of this error class will be returned when mongoose failed to
221
+ * populate with a path that is not existing.
222
+ *
223
+ * @api public
224
+ * @memberOf Error
225
+ * @static
226
+ */
227
+
228
+ MongooseError.StrictPopulateError = require('./strictPopulate');
@@ -16,7 +16,7 @@ const isSSLError = require('../helpers/topology/isSSLError');
16
16
  const atlasMessage = 'Could not connect to any servers in your MongoDB Atlas cluster. ' +
17
17
  'One common reason is that you\'re trying to access the database from ' +
18
18
  'an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas ' +
19
- 'cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/';
19
+ 'cluster\'s IP whitelist: https://www.mongodb.com/docs/atlas/security-whitelist/';
20
20
 
21
21
  const sslMessage = 'Mongoose is connecting with SSL enabled, but the server is ' +
22
22
  'not accepting SSL connections. Please ensure that the MongoDB server you are ' +
@@ -78,7 +78,7 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
78
78
 
79
79
  if (typeof def !== 'undefined') {
80
80
  doc_[piece] = def;
81
- doc.$__.activePaths.default(p);
81
+ applyChangeTracking(doc, p);
82
82
  }
83
83
  } else if (included) {
84
84
  // selected field
@@ -91,7 +91,7 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
91
91
 
92
92
  if (typeof def !== 'undefined') {
93
93
  doc_[piece] = def;
94
- doc.$__.activePaths.default(p);
94
+ applyChangeTracking(doc, p);
95
95
  }
96
96
  }
97
97
  } else {
@@ -104,7 +104,7 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
104
104
 
105
105
  if (typeof def !== 'undefined') {
106
106
  doc_[piece] = def;
107
- doc.$__.activePaths.default(p);
107
+ applyChangeTracking(doc, p);
108
108
  }
109
109
  }
110
110
  } else {
@@ -113,3 +113,14 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
113
113
  }
114
114
  }
115
115
  };
116
+
117
+ /*!
118
+ * ignore
119
+ */
120
+
121
+ function applyChangeTracking(doc, fullPath) {
122
+ doc.$__.activePaths.default(fullPath);
123
+ if (doc.$isSubdocument && doc.$isSingleNested && doc.$parent() != null) {
124
+ doc.$parent().$__.activePaths.default(doc.$__pathRelativeToParent(fullPath));
125
+ }
126
+ }
@@ -275,7 +275,7 @@ function isLiteral(val) {
275
275
  }
276
276
  if (typeof val === 'object' && val !== null && Object.keys(val).find(key => key[0] === '$')) {
277
277
  // The `$literal` expression can make an object a literal
278
- // https://docs.mongodb.com/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal
278
+ // https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal
279
279
  return val.$literal != null;
280
280
  }
281
281
  return true;
@@ -84,14 +84,6 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
84
84
  const op = ops[i];
85
85
  val = ret[op];
86
86
  hasDollarKey = hasDollarKey || op.startsWith('$');
87
- const toUnset = {};
88
- if (val != null) {
89
- for (const key of Object.keys(val)) {
90
- if (val[key] === undefined) {
91
- toUnset[key] = 1;
92
- }
93
- }
94
- }
95
87
 
96
88
  if (val &&
97
89
  typeof val === 'object' &&
@@ -108,10 +100,6 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
108
100
 
109
101
  if (op.startsWith('$') && utils.isEmptyObject(val)) {
110
102
  delete ret[op];
111
- if (op === '$set' && !utils.isEmptyObject(toUnset)) {
112
- // Unset all undefined values
113
- ret['$unset'] = toUnset;
114
- }
115
103
  }
116
104
  }
117
105