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.
- package/.eslintrc.json +5 -2
- package/dist/browser.umd.js +68579 -2
- package/lib/cast/date.js +1 -1
- package/lib/cast/decimal128.js +1 -1
- package/lib/cast/objectid.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/document.js +8 -2
- package/lib/drivers/node-mongodb-native/index.js +1 -1
- package/lib/error/parallelValidate.js +1 -1
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
- package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
- package/lib/helpers/arrayDepth.js +1 -1
- package/lib/helpers/cursor/eachAsync.js +1 -1
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/document/handleSpreadDoc.js +1 -1
- package/lib/helpers/each.js +1 -1
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getConstructorName.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isTextIndex.js +1 -1
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +1 -1
- package/lib/helpers/isPromise.js +1 -1
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/applyStaticHooks.js +1 -1
- package/lib/helpers/once.js +1 -1
- package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
- package/lib/helpers/path/parentPaths.js +1 -1
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/SkipPopulateValue.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
- package/lib/helpers/populate/assignVals.js +1 -1
- package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
- package/lib/helpers/populate/leanPopulateMap.js +1 -1
- package/lib/helpers/populate/lookupLocalFields.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
- package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
- package/lib/helpers/populate/validateRef.js +1 -1
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +1 -1
- package/lib/helpers/projection/applyProjection.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/parseProjection.js +1 -1
- package/lib/helpers/query/applyGlobalOption.js +1 -1
- package/lib/helpers/query/applyQueryMiddleware.js +1 -1
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/helpers/query/castFilterPath.js +1 -1
- package/lib/helpers/query/sanitizeFilter.js +1 -1
- package/lib/helpers/query/sanitizeProjection.js +1 -1
- package/lib/helpers/query/trusted.js +1 -1
- package/lib/helpers/query/validOps.js +1 -1
- package/lib/helpers/query/wrapThunk.js +1 -1
- package/lib/helpers/schema/addAutoId.js +1 -1
- package/lib/helpers/schema/applyPlugins.js +1 -1
- package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
- package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
- package/lib/helpers/schema/getPath.js +1 -1
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/handleTimestampOption.js +1 -1
- package/lib/helpers/specialProperties.js +1 -1
- package/lib/helpers/symbols.js +1 -1
- package/lib/helpers/timers.js +1 -1
- package/lib/helpers/timestamps/setupTimestamps.js +1 -1
- package/lib/helpers/topology/allServersUnknown.js +1 -1
- package/lib/helpers/topology/isAtlas.js +1 -1
- package/lib/helpers/topology/isSSLError.js +1 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/castArrayFilters.js +1 -1
- package/lib/helpers/update/moveImmutableProperties.js +1 -1
- package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
- package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
- package/lib/index.js +2 -2
- package/lib/options/PopulateOptions.js +1 -1
- package/lib/options/SchemaArrayOptions.js +1 -1
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDocumentArrayOptions.js +1 -1
- package/lib/options/SchemaMapOptions.js +1 -1
- package/lib/options/SchemaNumberOptions.js +1 -1
- package/lib/options/SchemaObjectIdOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +1 -1
- package/lib/options/VirtualOptions.js +1 -1
- package/lib/options/propertyOptions.js +1 -1
- package/lib/options/removeOptions.js +1 -1
- package/lib/options/saveOptions.js +1 -1
- package/lib/plugins/trackTransaction.js +1 -1
- package/lib/queryhelpers.js +5 -0
- package/lib/schema/array.js +1 -1
- package/lib/schema/date.js +2 -2
- package/lib/schema/number.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema/symbols.js +1 -1
- package/lib/schema.js +3 -3
- package/lib/schematype.js +2 -1
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/types/buffer.js +26 -28
- package/lib/types/decimal128.js +3 -3
- package/lib/types/map.js +70 -0
- package/package.json +11 -11
- package/types/collection.d.ts +1 -1
- package/types/document.d.ts +12 -6
- package/types/expressions.d.ts +30 -9
- package/types/index.d.ts +13 -12
- package/types/{indizes.d.ts → indexes.d.ts} +2 -2
- package/types/inferschematype.d.ts +51 -33
- package/types/middlewares.d.ts +1 -1
- package/types/models.d.ts +14 -14
- package/types/mongooseoptions.d.ts +1 -1
- package/types/pipelinestage.d.ts +2 -2
- package/types/query.d.ts +1 -1
- package/types/schemaoptions.d.ts +1 -1
- package/types/types.d.ts +3 -1
- package/types/utility.d.ts +8 -1
package/lib/queryhelpers.js
CHANGED
|
@@ -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;
|
package/lib/schema/array.js
CHANGED
|
@@ -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
|
|
package/lib/schema/date.js
CHANGED
|
@@ -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
|
|
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
|
package/lib/schema/number.js
CHANGED
|
@@ -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
|
|
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
|
package/lib/schema/string.js
CHANGED
|
@@ -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
|
|
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
|
package/lib/schema/symbols.js
CHANGED
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
|
*/
|
package/lib/types/buffer.js
CHANGED
|
@@ -70,7 +70,7 @@ MongooseBuffer.mixin = {
|
|
|
70
70
|
*
|
|
71
71
|
* @api private
|
|
72
72
|
* @property _subtype
|
|
73
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
250
|
+
* @memberOf MongooseBuffer
|
|
253
251
|
*/
|
|
254
252
|
|
|
255
253
|
MongooseBuffer.mixin.subtype = function(subtype) {
|
package/lib/types/decimal128.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Decimal128 type constructor
|
|
3
3
|
*
|
|
4
4
|
* #### Example
|
|
5
5
|
*
|
|
6
|
-
* const id = new mongoose.Types.
|
|
6
|
+
* const id = new mongoose.Types.Decimal128('3.1415');
|
|
7
7
|
*
|
|
8
|
-
* @constructor
|
|
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.
|
|
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.
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
33
|
-
"@typescript-eslint/parser": "5.
|
|
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.
|
|
43
|
+
"cheerio": "1.0.0-rc.12",
|
|
44
44
|
"crypto-browserify": "3.12.0",
|
|
45
45
|
"dox": "0.3.1",
|
|
46
|
-
"eslint": "8.
|
|
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.
|
|
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.
|
|
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.
|
|
65
|
-
"typescript": "4.7.
|
|
64
|
+
"tsd": "0.22.0",
|
|
65
|
+
"typescript": "4.7.4",
|
|
66
66
|
"uuid": "8.3.2",
|
|
67
|
-
"webpack": "5.
|
|
67
|
+
"webpack": "5.73.0"
|
|
68
68
|
},
|
|
69
69
|
"directories": {
|
|
70
70
|
"lib": "./lib/mongoose"
|
package/types/collection.d.ts
CHANGED
package/types/document.d.ts
CHANGED
|
@@ -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?:
|
|
78
|
-
$set(path: string, val: any, options?:
|
|
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
|
|
198
|
-
populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this
|
|
199
|
-
populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<this
|
|
200
|
-
populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<this
|
|
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;
|