mongoose 6.4.0 → 6.4.3

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.
Files changed (123) hide show
  1. package/.eslintrc.json +5 -2
  2. package/dist/browser.umd.js +68579 -2
  3. package/lib/cast/date.js +1 -1
  4. package/lib/cast/decimal128.js +1 -1
  5. package/lib/cast/objectid.js +1 -1
  6. package/lib/cast.js +1 -1
  7. package/lib/document.js +8 -2
  8. package/lib/drivers/node-mongodb-native/index.js +1 -1
  9. package/lib/error/parallelValidate.js +1 -1
  10. package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
  11. package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
  12. package/lib/helpers/arrayDepth.js +1 -1
  13. package/lib/helpers/cursor/eachAsync.js +1 -1
  14. package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
  15. package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
  16. package/lib/helpers/discriminator/getConstructor.js +1 -1
  17. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  18. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  19. package/lib/helpers/document/handleSpreadDoc.js +1 -1
  20. package/lib/helpers/each.js +1 -1
  21. package/lib/helpers/get.js +1 -1
  22. package/lib/helpers/getConstructorName.js +1 -1
  23. package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
  24. package/lib/helpers/indexes/applySchemaCollation.js +1 -1
  25. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  26. package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
  27. package/lib/helpers/indexes/isTextIndex.js +1 -1
  28. package/lib/helpers/isMongooseObject.js +1 -1
  29. package/lib/helpers/isObject.js +1 -1
  30. package/lib/helpers/isPromise.js +1 -1
  31. package/lib/helpers/model/applyHooks.js +1 -1
  32. package/lib/helpers/model/applyStaticHooks.js +1 -1
  33. package/lib/helpers/once.js +1 -1
  34. package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
  35. package/lib/helpers/path/parentPaths.js +1 -1
  36. package/lib/helpers/path/setDottedPath.js +1 -1
  37. package/lib/helpers/pluralize.js +1 -1
  38. package/lib/helpers/populate/SkipPopulateValue.js +1 -1
  39. package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
  40. package/lib/helpers/populate/assignVals.js +1 -1
  41. package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
  42. package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
  43. package/lib/helpers/populate/leanPopulateMap.js +1 -1
  44. package/lib/helpers/populate/lookupLocalFields.js +1 -1
  45. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  46. package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
  47. package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
  48. package/lib/helpers/populate/validateRef.js +1 -1
  49. package/lib/helpers/printJestWarning.js +1 -1
  50. package/lib/helpers/processConnectionOptions.js +1 -1
  51. package/lib/helpers/projection/applyProjection.js +1 -1
  52. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  53. package/lib/helpers/projection/parseProjection.js +1 -1
  54. package/lib/helpers/query/applyGlobalOption.js +1 -1
  55. package/lib/helpers/query/applyQueryMiddleware.js +1 -1
  56. package/lib/helpers/query/cast$expr.js +1 -1
  57. package/lib/helpers/query/castFilterPath.js +1 -1
  58. package/lib/helpers/query/sanitizeFilter.js +1 -1
  59. package/lib/helpers/query/sanitizeProjection.js +1 -1
  60. package/lib/helpers/query/trusted.js +1 -1
  61. package/lib/helpers/query/validOps.js +1 -1
  62. package/lib/helpers/query/wrapThunk.js +1 -1
  63. package/lib/helpers/schema/addAutoId.js +1 -1
  64. package/lib/helpers/schema/applyPlugins.js +1 -1
  65. package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
  66. package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
  67. package/lib/helpers/schema/getPath.js +1 -1
  68. package/lib/helpers/schema/handleIdOption.js +1 -1
  69. package/lib/helpers/schema/handleTimestampOption.js +1 -1
  70. package/lib/helpers/specialProperties.js +1 -1
  71. package/lib/helpers/symbols.js +1 -1
  72. package/lib/helpers/timers.js +1 -1
  73. package/lib/helpers/timestamps/setupTimestamps.js +1 -1
  74. package/lib/helpers/topology/allServersUnknown.js +1 -1
  75. package/lib/helpers/topology/isAtlas.js +1 -1
  76. package/lib/helpers/topology/isSSLError.js +1 -1
  77. package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
  78. package/lib/helpers/update/castArrayFilters.js +1 -1
  79. package/lib/helpers/update/moveImmutableProperties.js +1 -1
  80. package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
  81. package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
  82. package/lib/index.js +2 -2
  83. package/lib/options/PopulateOptions.js +1 -1
  84. package/lib/options/SchemaArrayOptions.js +1 -1
  85. package/lib/options/SchemaBufferOptions.js +1 -1
  86. package/lib/options/SchemaDocumentArrayOptions.js +1 -1
  87. package/lib/options/SchemaMapOptions.js +1 -1
  88. package/lib/options/SchemaNumberOptions.js +1 -1
  89. package/lib/options/SchemaObjectIdOptions.js +1 -1
  90. package/lib/options/SchemaSubdocumentOptions.js +1 -1
  91. package/lib/options/SchemaTypeOptions.js +1 -1
  92. package/lib/options/VirtualOptions.js +1 -1
  93. package/lib/options/propertyOptions.js +1 -1
  94. package/lib/options/removeOptions.js +1 -1
  95. package/lib/options/saveOptions.js +1 -1
  96. package/lib/plugins/trackTransaction.js +1 -1
  97. package/lib/queryhelpers.js +5 -0
  98. package/lib/schema/array.js +1 -1
  99. package/lib/schema/date.js +2 -2
  100. package/lib/schema/number.js +2 -2
  101. package/lib/schema/string.js +2 -2
  102. package/lib/schema/symbols.js +1 -1
  103. package/lib/schema.js +3 -3
  104. package/lib/schematype.js +2 -1
  105. package/lib/types/DocumentArray/methods/index.js +1 -1
  106. package/lib/types/buffer.js +26 -28
  107. package/lib/types/decimal128.js +3 -3
  108. package/lib/types/map.js +70 -0
  109. package/package.json +11 -11
  110. package/types/collection.d.ts +1 -1
  111. package/types/document.d.ts +12 -6
  112. package/types/expressions.d.ts +30 -9
  113. package/types/index.d.ts +13 -12
  114. package/types/{indizes.d.ts → indexes.d.ts} +2 -2
  115. package/types/inferschematype.d.ts +51 -33
  116. package/types/middlewares.d.ts +1 -1
  117. package/types/models.d.ts +14 -14
  118. package/types/mongooseoptions.d.ts +1 -1
  119. package/types/pipelinestage.d.ts +2 -2
  120. package/types/query.d.ts +1 -1
  121. package/types/schemaoptions.d.ts +1 -1
  122. package/types/types.d.ts +3 -1
  123. package/types/utility.d.ts +8 -1
@@ -56,4 +56,4 @@ Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
56
56
  * ignore
57
57
  */
58
58
 
59
- module.exports = SchemaArrayOptions;
59
+ module.exports = SchemaArrayOptions;
@@ -35,4 +35,4 @@ Object.defineProperty(SchemaBufferOptions.prototype, 'subtype', opts);
35
35
  * ignore
36
36
  */
37
37
 
38
- module.exports = SchemaBufferOptions;
38
+ module.exports = SchemaBufferOptions;
@@ -65,4 +65,4 @@ Object.defineProperty(SchemaDocumentArrayOptions.prototype, '_id', opts);
65
65
  * ignore
66
66
  */
67
67
 
68
- module.exports = SchemaDocumentArrayOptions;
68
+ module.exports = SchemaDocumentArrayOptions;
@@ -40,4 +40,4 @@ const opts = require('./propertyOptions');
40
40
 
41
41
  Object.defineProperty(SchemaMapOptions.prototype, 'of', opts);
42
42
 
43
- module.exports = SchemaMapOptions;
43
+ module.exports = SchemaMapOptions;
@@ -96,4 +96,4 @@ Object.defineProperty(SchemaNumberOptions.prototype, 'populate', opts);
96
96
  * ignore
97
97
  */
98
98
 
99
- module.exports = SchemaNumberOptions;
99
+ module.exports = SchemaNumberOptions;
@@ -60,4 +60,4 @@ Object.defineProperty(SchemaObjectIdOptions.prototype, 'populate', opts);
60
60
  * ignore
61
61
  */
62
62
 
63
- module.exports = SchemaObjectIdOptions;
63
+ module.exports = SchemaObjectIdOptions;
@@ -39,4 +39,4 @@ const opts = require('./propertyOptions');
39
39
 
40
40
  Object.defineProperty(SchemaSubdocumentOptions.prototype, '_id', opts);
41
41
 
42
- module.exports = SchemaSubdocumentOptions;
42
+ module.exports = SchemaSubdocumentOptions;
@@ -241,4 +241,4 @@ Object.defineProperty(SchemaTypeOptions.prototype, 'text', opts);
241
241
 
242
242
  Object.defineProperty(SchemaTypeOptions.prototype, 'transform', opts);
243
243
 
244
- module.exports = SchemaTypeOptions;
244
+ module.exports = SchemaTypeOptions;
@@ -161,4 +161,4 @@ Object.defineProperty(VirtualOptions.prototype, 'limit', opts);
161
161
 
162
162
  Object.defineProperty(VirtualOptions.prototype, 'perDocumentLimit', opts);
163
163
 
164
- module.exports = VirtualOptions;
164
+ module.exports = VirtualOptions;
@@ -5,4 +5,4 @@ module.exports = Object.freeze({
5
5
  configurable: true,
6
6
  writable: true,
7
7
  value: void 0
8
- });
8
+ });
@@ -11,4 +11,4 @@ class RemoveOptions {
11
11
  }
12
12
  }
13
13
 
14
- module.exports = RemoveOptions;
14
+ module.exports = RemoveOptions;
@@ -11,4 +11,4 @@ class SaveOptions {
11
11
  }
12
12
  }
13
13
 
14
- module.exports = SaveOptions;
14
+ module.exports = SaveOptions;
@@ -89,4 +89,4 @@ function mergeAtomics(destination, source) {
89
89
  }
90
90
 
91
91
  return destination;
92
- }
92
+ }
@@ -209,6 +209,11 @@ exports.applyPaths = function applyPaths(fields, schema) {
209
209
  // user didn't specify fields, implies returning all fields.
210
210
  // only need to apply excluded fields and delete any plus paths
211
211
  for (const fieldName of excluded) {
212
+ if (fields[fieldName] != null) {
213
+ // Skip applying default projections to fields with non-defining
214
+ // projections, like `$slice`
215
+ continue;
216
+ }
212
217
  fields[fieldName] = 0;
213
218
  }
214
219
  break;
@@ -212,7 +212,7 @@ SchemaArray.checkRequired = SchemaType.checkRequired;
212
212
  */
213
213
 
214
214
  SchemaArray.prototype.checkRequired = function checkRequired(value, doc) {
215
- if (SchemaType._isRef(this, value, doc, true)) {
215
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
216
216
  return !!value;
217
217
  }
218
218
 
@@ -195,8 +195,8 @@ SchemaDate.checkRequired = SchemaType.checkRequired;
195
195
  */
196
196
 
197
197
  SchemaDate.prototype.checkRequired = function(value, doc) {
198
- if (SchemaType._isRef(this, value, doc, true)) {
199
- return !!value;
198
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
199
+ return value != null;
200
200
  }
201
201
 
202
202
  // `require('util').inherits()` does **not** copy static properties, and
@@ -164,8 +164,8 @@ SchemaNumber.checkRequired = SchemaType.checkRequired;
164
164
  */
165
165
 
166
166
  SchemaNumber.prototype.checkRequired = function checkRequired(value, doc) {
167
- if (SchemaType._isRef(this, value, doc, true)) {
168
- return !!value;
167
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
168
+ return value != null;
169
169
  }
170
170
 
171
171
  // `require('util').inherits()` does **not** copy static properties, and
@@ -561,8 +561,8 @@ SchemaString.prototype.match = function match(regExp, message) {
561
561
  */
562
562
 
563
563
  SchemaString.prototype.checkRequired = function checkRequired(value, doc) {
564
- if (SchemaType._isRef(this, value, doc, true)) {
565
- return !!value;
564
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
565
+ return value != null;
566
566
  }
567
567
 
568
568
  // `require('util').inherits()` does **not** copy static properties, and
@@ -2,4 +2,4 @@
2
2
 
3
3
  exports.schemaMixedSymbol = Symbol.for('mongoose:schema_mixed');
4
4
 
5
- exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
5
+ exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
package/lib/schema.js CHANGED
@@ -477,7 +477,7 @@ Schema.prototype.defaultOptions = function(options) {
477
477
  * Inherit a Schema by applying a discriminator on an existing Schema.
478
478
  *
479
479
  *
480
- * ####Example:
480
+ * #### Example:
481
481
  *
482
482
  * const options = { discriminatorKey: 'kind' };
483
483
  *
@@ -648,7 +648,7 @@ Schema.prototype.add = function add(obj, prefix) {
648
648
  * removeIndex only removes indexes from your schema object. Does **not** affect the indexes
649
649
  * in MongoDB.
650
650
  *
651
- * ####Example:
651
+ * #### Example:
652
652
  *
653
653
  * const ToySchema = new Schema({ name: String, color: String, price: Number });
654
654
  *
@@ -701,7 +701,7 @@ Schema.prototype.removeIndex = function removeIndex(index) {
701
701
  * clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
702
702
  * in MongoDB.
703
703
  *
704
- * ####Example:
704
+ * #### Example:
705
705
  *
706
706
  * const ToySchema = new Schema({ name: String, color: String, price: Number });
707
707
  * ToySchema.index({ name: 1 });
package/lib/schematype.js CHANGED
@@ -384,6 +384,7 @@ SchemaType.prototype.default = function(val) {
384
384
  * #### Example:
385
385
  *
386
386
  * const s = new Schema({ name: { type: String, index: true })
387
+ * const s = new Schema({ name: { type: String, index: -1 })
387
388
  * const s = new Schema({ loc: { type: [Number], index: 'hashed' })
388
389
  * const s = new Schema({ loc: { type: [Number], index: '2d', sparse: true })
389
390
  * const s = new Schema({ loc: { type: [Number], index: { type: '2dsphere', sparse: true }})
@@ -399,7 +400,7 @@ SchemaType.prototype.default = function(val) {
399
400
  * read/write operations you send until the index build.
400
401
  * Specify `background: false` to override Mongoose's default._
401
402
  *
402
- * @param {Object|Boolean|String} options
403
+ * @param {Object|Boolean|String|Number} options
403
404
  * @return {SchemaType} this
404
405
  * @api public
405
406
  */
@@ -376,4 +376,4 @@ function _updateParentPopulated(arr) {
376
376
 
377
377
  parent.$__.populated[path].value = arr.map(val => val.$populated(remnant));
378
378
  }
379
- }
379
+ }
@@ -70,7 +70,7 @@ MongooseBuffer.mixin = {
70
70
  *
71
71
  * @api private
72
72
  * @property _subtype
73
- * @receiver MongooseBuffer
73
+ * @memberOf MongooseBuffer
74
74
  */
75
75
 
76
76
  _subtype: undefined,
@@ -80,7 +80,7 @@ MongooseBuffer.mixin = {
80
80
  *
81
81
  * @api private
82
82
  * @method _markModified
83
- * @receiver MongooseBuffer
83
+ * @memberOf MongooseBuffer
84
84
  */
85
85
 
86
86
  _markModified: function() {
@@ -97,7 +97,7 @@ MongooseBuffer.mixin = {
97
97
  *
98
98
  * @api public
99
99
  * @method write
100
- * @receiver MongooseBuffer
100
+ * @memberOf MongooseBuffer
101
101
  */
102
102
 
103
103
  write: function() {
@@ -120,7 +120,7 @@ MongooseBuffer.mixin = {
120
120
  * @return {Number} The number of bytes copied.
121
121
  * @param {Buffer} target
122
122
  * @method copy
123
- * @receiver MongooseBuffer
123
+ * @memberOf MongooseBuffer
124
124
  */
125
125
 
126
126
  copy: function(target) {
@@ -161,24 +161,22 @@ MongooseBuffer.mixin = {
161
161
  /**
162
162
  * Converts this buffer to its Binary type representation.
163
163
  *
164
- * ####SubTypes:
165
- *
166
- * const bson = require('bson')
167
- * bson.BSON_BINARY_SUBTYPE_DEFAULT
168
- * bson.BSON_BINARY_SUBTYPE_FUNCTION
169
- * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
170
- * bson.BSON_BINARY_SUBTYPE_UUID
171
- * bson.BSON_BINARY_SUBTYPE_MD5
172
- * bson.BSON_BINARY_SUBTYPE_USER_DEFINED
173
- *
174
- * doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
164
+ * #### SubTypes:
165
+ * const bson = require('bson')
166
+ * bson.BSON_BINARY_SUBTYPE_DEFAULT
167
+ * bson.BSON_BINARY_SUBTYPE_FUNCTION
168
+ * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
169
+ * bson.BSON_BINARY_SUBTYPE_UUID
170
+ * bson.BSON_BINARY_SUBTYPE_MD5
171
+ * bson.BSON_BINARY_SUBTYPE_USER_DEFINED
172
+ * doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
175
173
  *
176
174
  * @see https://bsonspec.org/#/specification
177
175
  * @param {Hex} [subtype]
178
176
  * @return {Binary}
179
177
  * @api public
180
178
  * @method toObject
181
- * @receiver MongooseBuffer
179
+ * @memberOf MongooseBuffer
182
180
  */
183
181
 
184
182
  MongooseBuffer.mixin.toObject = function(options) {
@@ -196,7 +194,7 @@ MongooseBuffer.mixin.$toObject = MongooseBuffer.mixin.toObject;
196
194
  * @return {Binary}
197
195
  * @api public
198
196
  * @method toBSON
199
- * @receiver MongooseBuffer
197
+ * @memberOf MongooseBuffer
200
198
  */
201
199
 
202
200
  MongooseBuffer.mixin.toBSON = function() {
@@ -209,7 +207,7 @@ MongooseBuffer.mixin.toBSON = function() {
209
207
  * @param {Buffer} other
210
208
  * @return {Boolean}
211
209
  * @method equals
212
- * @receiver MongooseBuffer
210
+ * @memberOf MongooseBuffer
213
211
  */
214
212
 
215
213
  MongooseBuffer.mixin.equals = function(other) {
@@ -233,23 +231,23 @@ MongooseBuffer.mixin.equals = function(other) {
233
231
  /**
234
232
  * Sets the subtype option and marks the buffer modified.
235
233
  *
236
- * ####SubTypes:
234
+ * #### SubTypes:
237
235
  *
238
- * const bson = require('bson')
239
- * bson.BSON_BINARY_SUBTYPE_DEFAULT
240
- * bson.BSON_BINARY_SUBTYPE_FUNCTION
241
- * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
242
- * bson.BSON_BINARY_SUBTYPE_UUID
243
- * bson.BSON_BINARY_SUBTYPE_MD5
244
- * bson.BSON_BINARY_SUBTYPE_USER_DEFINED
236
+ * const bson = require('bson')
237
+ * bson.BSON_BINARY_SUBTYPE_DEFAULT
238
+ * bson.BSON_BINARY_SUBTYPE_FUNCTION
239
+ * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
240
+ * bson.BSON_BINARY_SUBTYPE_UUID
241
+ * bson.BSON_BINARY_SUBTYPE_MD5
242
+ * bson.BSON_BINARY_SUBTYPE_USER_DEFINED
245
243
  *
246
- * doc.buffer.subtype(bson.BSON_BINARY_SUBTYPE_UUID);
244
+ * doc.buffer.subtype(bson.BSON_BINARY_SUBTYPE_UUID);
247
245
  *
248
246
  * @see https://bsonspec.org/#/specification
249
247
  * @param {Hex} subtype
250
248
  * @api public
251
249
  * @method subtype
252
- * @receiver MongooseBuffer
250
+ * @memberOf MongooseBuffer
253
251
  */
254
252
 
255
253
  MongooseBuffer.mixin.subtype = function(subtype) {
@@ -1,11 +1,11 @@
1
1
  /**
2
- * ObjectId type constructor
2
+ * Decimal128 type constructor
3
3
  *
4
4
  * #### Example
5
5
  *
6
- * const id = new mongoose.Types.ObjectId;
6
+ * const id = new mongoose.Types.Decimal128('3.1415');
7
7
  *
8
- * @constructor ObjectId
8
+ * @constructor Decimal128
9
9
  */
10
10
 
11
11
  'use strict';
package/lib/types/map.js CHANGED
@@ -42,6 +42,14 @@ class MongooseMap extends Map {
42
42
  super.set(key, value);
43
43
  }
44
44
 
45
+ /**
46
+ * Overwrites native Map's `get()` function to support Mongoose getters.
47
+ *
48
+ * @api public
49
+ * @method get
50
+ * @memberOf Map
51
+ */
52
+
45
53
  get(key, options) {
46
54
  if (isBsonType(key, 'ObjectID')) {
47
55
  key = key.toString();
@@ -54,6 +62,20 @@ class MongooseMap extends Map {
54
62
  return this.$__schemaType.applyGetters(super.get(key), this.$__parent);
55
63
  }
56
64
 
65
+ /**
66
+ * Overwrites native Map's `set()` function to support setters, `populate()`,
67
+ * and change tracking. Note that Mongoose maps _only_ support strings and
68
+ * ObjectIds as keys.
69
+ *
70
+ * #### Example:
71
+ * doc.myMap.set('test', 42); // works
72
+ * doc.myMap.set({ obj: 42 }, 42); // Throws "Mongoose maps only support string keys"
73
+ *
74
+ * @api public
75
+ * @method set
76
+ * @memberOf Map
77
+ */
78
+
57
79
  set(key, value) {
58
80
  if (isBsonType(key, 'ObjectID')) {
59
81
  key = key.toString();
@@ -108,6 +130,14 @@ class MongooseMap extends Map {
108
130
  }
109
131
  }
110
132
 
133
+ /**
134
+ * Overwrites native Map's `clear()` function to support change tracking.
135
+ *
136
+ * @api public
137
+ * @method clear
138
+ * @memberOf Map
139
+ */
140
+
111
141
  clear() {
112
142
  super.clear();
113
143
  const parent = this.$__parent;
@@ -116,6 +146,14 @@ class MongooseMap extends Map {
116
146
  }
117
147
  }
118
148
 
149
+ /**
150
+ * Overwrites native Map's `delete()` function to support change tracking.
151
+ *
152
+ * @api public
153
+ * @method delete
154
+ * @memberOf Map
155
+ */
156
+
119
157
  delete(key) {
120
158
  if (isBsonType(key, 'ObjectID')) {
121
159
  key = key.toString();
@@ -125,6 +163,14 @@ class MongooseMap extends Map {
125
163
  super.delete(key);
126
164
  }
127
165
 
166
+ /**
167
+ * Converts this map to a native JavaScript Map so the MongoDB driver can serialize it.
168
+ *
169
+ * @api public
170
+ * @method toBSON
171
+ * @memberOf Map
172
+ */
173
+
128
174
  toBSON() {
129
175
  return new Map(this);
130
176
  }
@@ -146,6 +192,21 @@ class MongooseMap extends Map {
146
192
  return this.constructor.prototype.toObject.apply(this, arguments);
147
193
  }
148
194
 
195
+ /**
196
+ * Converts this map to a native JavaScript Map for `JSON.stringify()`. Set
197
+ * the `flattenMaps` option to convert this map to a POJO instead.
198
+ *
199
+ * #### Example:
200
+ * doc.myMap.toJSON() instanceof Map; // true
201
+ * doc.myMap.toJSON({ flattenMaps: true }) instanceof Map; // false
202
+ *
203
+ * @api public
204
+ * @method toJSON
205
+ * @param {Object} [options]
206
+ * @param {Boolean} [options.flattenMaps=false] set to `true` to convert the map to a POJO rather than a native JavaScript map
207
+ * @memberOf Map
208
+ */
209
+
149
210
  toJSON(options) {
150
211
  if (typeof (options && options.flattenMaps) === 'boolean' ? options.flattenMaps : true) {
151
212
  const ret = {};
@@ -209,6 +270,15 @@ Object.defineProperty(MongooseMap.prototype, '$__schemaType', {
209
270
  configurable: false
210
271
  });
211
272
 
273
+ /**
274
+ * Set to `true` for all Mongoose map instances
275
+ *
276
+ * @api public
277
+ * @property $isMongooseMap
278
+ * @memberOf Map
279
+ * @instance
280
+ */
281
+
212
282
  Object.defineProperty(MongooseMap.prototype, '$isMongooseMap', {
213
283
  enumerable: false,
214
284
  writable: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.4.0",
4
+ "version": "6.4.3",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -28,9 +28,9 @@
28
28
  "sift": "16.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/core": "7.18.2",
32
- "@typescript-eslint/eslint-plugin": "5.27.0",
33
- "@typescript-eslint/parser": "5.27.0",
31
+ "@babel/core": "7.18.6",
32
+ "@typescript-eslint/eslint-plugin": "5.30.3",
33
+ "@typescript-eslint/parser": "5.30.3",
34
34
  "acquit": "1.2.1",
35
35
  "acquit-ignore": "0.2.0",
36
36
  "acquit-require": "0.1.1",
@@ -40,19 +40,19 @@
40
40
  "benchmark": "2.1.4",
41
41
  "bluebird": "3.7.2",
42
42
  "buffer": "^5.6.0",
43
- "cheerio": "1.0.0-rc.11",
43
+ "cheerio": "1.0.0-rc.12",
44
44
  "crypto-browserify": "3.12.0",
45
45
  "dox": "0.3.1",
46
- "eslint": "8.16.0",
46
+ "eslint": "8.19.0",
47
47
  "eslint-plugin-mocha-no-only": "1.1.1",
48
48
  "highlight.js": "11.5.1",
49
49
  "lodash.isequal": "4.5.0",
50
50
  "lodash.isequalwith": "4.4.0",
51
- "marked": "4.0.16",
51
+ "marked": "4.0.17",
52
52
  "mkdirp": "^1.0.4",
53
53
  "mocha": "10.0.0",
54
54
  "moment": "2.x",
55
- "mongodb-memory-server": "8.6.0",
55
+ "mongodb-memory-server": "8.7.2",
56
56
  "ncp": "^2.0.0",
57
57
  "nyc": "15.1.0",
58
58
  "pug": "3.0.2",
@@ -61,10 +61,10 @@
61
61
  "sinon": "14.0.0",
62
62
  "stream-browserify": "3.0.0",
63
63
  "ts-benchmark": "^1.0.2",
64
- "tsd": "0.20.0",
65
- "typescript": "4.7.2",
64
+ "tsd": "0.22.0",
65
+ "typescript": "4.7.4",
66
66
  "uuid": "8.3.2",
67
- "webpack": "5.72.1"
67
+ "webpack": "5.73.0"
68
68
  },
69
69
  "directories": {
70
70
  "lib": "./lib/mongoose"
@@ -43,4 +43,4 @@ declare module 'mongoose' {
43
43
  getIndexes(): ReturnType<mongodb.Collection<T>['indexInformation']>;
44
44
  }
45
45
  let Collection: Collection;
46
- }
46
+ }
@@ -4,6 +4,12 @@ declare module 'mongoose' {
4
4
  /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */
5
5
  type pathsToSkip = string[] | string;
6
6
 
7
+ interface DocumentSetOptions {
8
+ merge?: boolean;
9
+
10
+ [key: string]: any;
11
+ }
12
+
7
13
  /**
8
14
  * Generic types for Document:
9
15
  * * T - the type of _id
@@ -74,8 +80,8 @@ declare module 'mongoose' {
74
80
  $session(session?: ClientSession | null): ClientSession | null;
75
81
 
76
82
  /** Alias for `set()`, used internally to avoid conflicts */
77
- $set(path: string, val: any, type: any, options?: any): this;
78
- $set(path: string, val: any, options?: any): this;
83
+ $set(path: string, val: any, type: any, options?: DocumentSetOptions): this;
84
+ $set(path: string, val: any, options?: DocumentSetOptions): this;
79
85
  $set(value: any): this;
80
86
 
81
87
  /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */
@@ -194,10 +200,10 @@ declare module 'mongoose' {
194
200
  $parent(): Document | undefined;
195
201
 
196
202
  /** Populates document references. */
197
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this & Paths>;
198
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this & Paths>): void;
199
- populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<this & Paths>;
200
- populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<this & Paths>): void;
203
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<MergeType<this, Paths>>;
204
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<MergeType<this, Paths>>): void;
205
+ populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<MergeType<this, Paths>>;
206
+ populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<MergeType<this, Paths>>): void;
201
207
 
202
208
  /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
203
209
  populated(path: string): any;