mongoose 6.2.9 → 6.2.10
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/CHANGELOG.md +6 -0
- package/dist/browser.umd.js +2 -2
- package/lib/aggregate.js +36 -36
- package/lib/browser.js +4 -4
- package/lib/connection.js +21 -21
- package/lib/cursor/AggregationCursor.js +2 -2
- package/lib/cursor/QueryCursor.js +3 -3
- package/lib/document.js +36 -36
- package/lib/error/index.js +2 -2
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/index.js +23 -23
- package/lib/model.js +83 -77
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +2 -2
- package/lib/options/SchemaDocumentArrayOptions.js +3 -3
- package/lib/options/SchemaMapOptions.js +2 -2
- package/lib/options/SchemaNumberOptions.js +3 -3
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +2 -2
- package/lib/options/SchemaTypeOptions.js +3 -3
- package/lib/query.js +214 -223
- package/lib/schema/SubdocumentPath.js +2 -2
- package/lib/schema/array.js +2 -2
- package/lib/schema/boolean.js +4 -4
- package/lib/schema/buffer.js +3 -3
- package/lib/schema/date.js +7 -7
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +3 -3
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +6 -6
- package/lib/schema/objectid.js +4 -4
- package/lib/schema/string.js +14 -14
- package/lib/schema.js +28 -28
- package/lib/schematype.js +75 -67
- package/lib/types/ArraySubdocument.js +1 -1
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/buffer.js +1 -1
- package/lib/types/decimal128.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +2 -2
- package/lib/virtualtype.js +3 -3
- package/package.json +10 -10
- package/types/index.d.ts +5 -3
|
@@ -283,7 +283,7 @@ SubdocumentPath.prototype.doValidateSync = function(value, scope, options) {
|
|
|
283
283
|
/**
|
|
284
284
|
* Adds a discriminator to this single nested subdocument.
|
|
285
285
|
*
|
|
286
|
-
* ####Example:
|
|
286
|
+
* #### Example:
|
|
287
287
|
* const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
|
|
288
288
|
* const schema = Schema({ shape: shapeSchema });
|
|
289
289
|
*
|
|
@@ -321,7 +321,7 @@ SubdocumentPath.prototype.discriminator = function(name, schema, options) {
|
|
|
321
321
|
/**
|
|
322
322
|
* Sets a default option for all SubdocumentPath instances.
|
|
323
323
|
*
|
|
324
|
-
* ####Example:
|
|
324
|
+
* #### Example:
|
|
325
325
|
*
|
|
326
326
|
* // Make all numbers have option `min` equal to 0.
|
|
327
327
|
* mongoose.Schema.Embedded.set('required', true);
|
package/lib/schema/array.js
CHANGED
|
@@ -153,7 +153,7 @@ SchemaArray.defaultOptions = {};
|
|
|
153
153
|
/**
|
|
154
154
|
* Sets a default option for all Array instances.
|
|
155
155
|
*
|
|
156
|
-
* ####Example:
|
|
156
|
+
* #### Example:
|
|
157
157
|
*
|
|
158
158
|
* // Make all Array instances have `required` of true by default.
|
|
159
159
|
* mongoose.Schema.Array.set('required', true);
|
|
@@ -186,7 +186,7 @@ SchemaArray._checkRequired = SchemaType.prototype.checkRequired;
|
|
|
186
186
|
* Override the function the required validator uses to check whether an array
|
|
187
187
|
* passes the `required` check.
|
|
188
188
|
*
|
|
189
|
-
* ####Example:
|
|
189
|
+
* #### Example:
|
|
190
190
|
*
|
|
191
191
|
* // Require non-empty array to pass `required` check
|
|
192
192
|
* mongoose.Schema.Types.Array.checkRequired(v => Array.isArray(v) && v.length);
|
package/lib/schema/boolean.js
CHANGED
|
@@ -47,7 +47,7 @@ SchemaBoolean._cast = castBoolean;
|
|
|
47
47
|
/**
|
|
48
48
|
* Sets a default option for all Boolean instances.
|
|
49
49
|
*
|
|
50
|
-
* ####Example:
|
|
50
|
+
* #### Example:
|
|
51
51
|
*
|
|
52
52
|
* // Make all booleans have `default` of false.
|
|
53
53
|
* mongoose.Schema.Boolean.set('default', false);
|
|
@@ -68,7 +68,7 @@ SchemaBoolean.set = SchemaType.set;
|
|
|
68
68
|
/**
|
|
69
69
|
* Get/set the function used to cast arbitrary values to booleans.
|
|
70
70
|
*
|
|
71
|
-
* ####Example:
|
|
71
|
+
* #### Example:
|
|
72
72
|
*
|
|
73
73
|
* // Make Mongoose cast empty string '' to false.
|
|
74
74
|
* const original = mongoose.Schema.Boolean.cast();
|
|
@@ -148,7 +148,7 @@ SchemaBoolean.prototype.checkRequired = function(value) {
|
|
|
148
148
|
/**
|
|
149
149
|
* Configure which values get casted to `true`.
|
|
150
150
|
*
|
|
151
|
-
* ####Example:
|
|
151
|
+
* #### Example:
|
|
152
152
|
*
|
|
153
153
|
* const M = mongoose.model('Test', new Schema({ b: Boolean }));
|
|
154
154
|
* new M({ b: 'affirmative' }).b; // undefined
|
|
@@ -168,7 +168,7 @@ Object.defineProperty(SchemaBoolean, 'convertToTrue', {
|
|
|
168
168
|
/**
|
|
169
169
|
* Configure which values get casted to `false`.
|
|
170
170
|
*
|
|
171
|
-
* ####Example:
|
|
171
|
+
* #### Example:
|
|
172
172
|
*
|
|
173
173
|
* const M = mongoose.model('Test', new Schema({ b: Boolean }));
|
|
174
174
|
* new M({ b: 'nay' }).b; // undefined
|
package/lib/schema/buffer.js
CHANGED
|
@@ -52,7 +52,7 @@ SchemaBuffer._checkRequired = v => !!(v && v.length);
|
|
|
52
52
|
/**
|
|
53
53
|
* Sets a default option for all Buffer instances.
|
|
54
54
|
*
|
|
55
|
-
* ####Example:
|
|
55
|
+
* #### Example:
|
|
56
56
|
*
|
|
57
57
|
* // Make all buffers have `required` of true by default.
|
|
58
58
|
* mongoose.Schema.Buffer.set('required', true);
|
|
@@ -74,7 +74,7 @@ SchemaBuffer.set = SchemaType.set;
|
|
|
74
74
|
* Override the function the required validator uses to check whether a string
|
|
75
75
|
* passes the `required` check.
|
|
76
76
|
*
|
|
77
|
-
* ####Example:
|
|
77
|
+
* #### Example:
|
|
78
78
|
*
|
|
79
79
|
* // Allow empty strings to pass `required` check
|
|
80
80
|
* mongoose.Schema.Types.String.checkRequired(v => v != null);
|
|
@@ -204,7 +204,7 @@ SchemaBuffer.prototype.cast = function(value, doc, init) {
|
|
|
204
204
|
* Sets the default [subtype](https://studio3t.com/whats-new/best-practices-uuid-mongodb/)
|
|
205
205
|
* for this buffer. You can find a [list of allowed subtypes here](https://api.mongodb.com/python/current/api/bson/binary.html).
|
|
206
206
|
*
|
|
207
|
-
* ####Example:
|
|
207
|
+
* #### Example:
|
|
208
208
|
*
|
|
209
209
|
* const s = new Schema({ uuid: { type: Buffer, subtype: 4 });
|
|
210
210
|
* const M = db.model('M', s);
|
package/lib/schema/date.js
CHANGED
|
@@ -52,7 +52,7 @@ SchemaDate._cast = castDate;
|
|
|
52
52
|
/**
|
|
53
53
|
* Sets a default option for all Date instances.
|
|
54
54
|
*
|
|
55
|
-
* ####Example:
|
|
55
|
+
* #### Example:
|
|
56
56
|
*
|
|
57
57
|
* // Make all dates have `required` of true by default.
|
|
58
58
|
* mongoose.Schema.Date.set('required', true);
|
|
@@ -73,7 +73,7 @@ SchemaDate.set = SchemaType.set;
|
|
|
73
73
|
/**
|
|
74
74
|
* Get/set the function used to cast arbitrary values to dates.
|
|
75
75
|
*
|
|
76
|
-
* ####Example:
|
|
76
|
+
* #### Example:
|
|
77
77
|
*
|
|
78
78
|
* // Mongoose converts empty string '' into `null` for date types. You
|
|
79
79
|
* // can create a custom caster to disable it.
|
|
@@ -122,14 +122,14 @@ SchemaDate._defaultCaster = v => {
|
|
|
122
122
|
* This sets the `expireAfterSeconds` index option available in MongoDB >= 2.1.2.
|
|
123
123
|
* This index type is only compatible with Date types.
|
|
124
124
|
*
|
|
125
|
-
* ####Example:
|
|
125
|
+
* #### Example:
|
|
126
126
|
*
|
|
127
127
|
* // expire in 24 hours
|
|
128
128
|
* new Schema({ createdAt: { type: Date, expires: 60*60*24 }});
|
|
129
129
|
*
|
|
130
130
|
* `expires` utilizes the `ms` module from [guille](https://github.com/guille/) allowing us to use a friendlier syntax:
|
|
131
131
|
*
|
|
132
|
-
* ####Example:
|
|
132
|
+
* #### Example:
|
|
133
133
|
*
|
|
134
134
|
* // expire in 24 hours
|
|
135
135
|
* new Schema({ createdAt: { type: Date, expires: '24h' }});
|
|
@@ -167,7 +167,7 @@ SchemaDate._checkRequired = v => v instanceof Date;
|
|
|
167
167
|
* Override the function the required validator uses to check whether a string
|
|
168
168
|
* passes the `required` check.
|
|
169
169
|
*
|
|
170
|
-
* ####Example:
|
|
170
|
+
* #### Example:
|
|
171
171
|
*
|
|
172
172
|
* // Allow empty strings to pass `required` check
|
|
173
173
|
* mongoose.Schema.Types.String.checkRequired(v => v != null);
|
|
@@ -210,7 +210,7 @@ SchemaDate.prototype.checkRequired = function(value, doc) {
|
|
|
210
210
|
/**
|
|
211
211
|
* Sets a minimum date validator.
|
|
212
212
|
*
|
|
213
|
-
* ####Example:
|
|
213
|
+
* #### Example:
|
|
214
214
|
*
|
|
215
215
|
* const s = new Schema({ d: { type: Date, min: Date('1970-01-01') })
|
|
216
216
|
* const M = db.model('M', s)
|
|
@@ -272,7 +272,7 @@ SchemaDate.prototype.min = function(value, message) {
|
|
|
272
272
|
/**
|
|
273
273
|
* Sets a maximum date validator.
|
|
274
274
|
*
|
|
275
|
-
* ####Example:
|
|
275
|
+
* #### Example:
|
|
276
276
|
*
|
|
277
277
|
* const s = new Schema({ d: { type: Date, max: Date('2014-01-01') })
|
|
278
278
|
* const M = db.model('M', s)
|
package/lib/schema/decimal128.js
CHANGED
|
@@ -48,7 +48,7 @@ Decimal128._cast = castDecimal128;
|
|
|
48
48
|
/**
|
|
49
49
|
* Sets a default option for all Decimal128 instances.
|
|
50
50
|
*
|
|
51
|
-
* ####Example:
|
|
51
|
+
* #### Example:
|
|
52
52
|
*
|
|
53
53
|
* // Make all decimal 128s have `required` of true by default.
|
|
54
54
|
* mongoose.Schema.Decimal128.set('required', true);
|
|
@@ -69,7 +69,7 @@ Decimal128.set = SchemaType.set;
|
|
|
69
69
|
/**
|
|
70
70
|
* Get/set the function used to cast arbitrary values to decimals.
|
|
71
71
|
*
|
|
72
|
-
* ####Example:
|
|
72
|
+
* #### Example:
|
|
73
73
|
*
|
|
74
74
|
* // Make Mongoose only refuse to cast numbers as decimal128
|
|
75
75
|
* const original = mongoose.Schema.Types.Decimal128.cast();
|
|
@@ -152,7 +152,7 @@ function _createConstructor(schema, options, baseClass) {
|
|
|
152
152
|
/**
|
|
153
153
|
* Adds a discriminator to this document array.
|
|
154
154
|
*
|
|
155
|
-
* ####Example:
|
|
155
|
+
* #### Example:
|
|
156
156
|
* const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
|
|
157
157
|
* const schema = Schema({ shapes: [shapeSchema] });
|
|
158
158
|
*
|
|
@@ -274,7 +274,7 @@ DocumentArrayPath.prototype.doValidate = function(array, fn, scope, options) {
|
|
|
274
274
|
/**
|
|
275
275
|
* Performs local validations first, then validations on each embedded doc.
|
|
276
276
|
*
|
|
277
|
-
* ####Note:
|
|
277
|
+
* #### Note:
|
|
278
278
|
*
|
|
279
279
|
* This method ignores the asynchronous validators.
|
|
280
280
|
*
|
|
@@ -565,7 +565,7 @@ function scopePaths(array, fields, init) {
|
|
|
565
565
|
/**
|
|
566
566
|
* Sets a default option for all DocumentArray instances.
|
|
567
567
|
*
|
|
568
|
-
* ####Example:
|
|
568
|
+
* #### Example:
|
|
569
569
|
*
|
|
570
570
|
* // Make all numbers have option `min` equal to 0.
|
|
571
571
|
* mongoose.Schema.DocumentArray.set('_id', false);
|
package/lib/schema/mixed.js
CHANGED
|
@@ -56,7 +56,7 @@ Mixed.prototype.constructor = Mixed;
|
|
|
56
56
|
/**
|
|
57
57
|
* Attaches a getter for all Mixed paths.
|
|
58
58
|
*
|
|
59
|
-
* ####Example:
|
|
59
|
+
* #### Example:
|
|
60
60
|
*
|
|
61
61
|
* // Hide the 'hidden' path
|
|
62
62
|
* mongoose.Schema.Mixed.get(v => Object.assign({}, v, { hidden: null }));
|
|
@@ -76,7 +76,7 @@ Mixed.get = SchemaType.get;
|
|
|
76
76
|
/**
|
|
77
77
|
* Sets a default option for all Mixed instances.
|
|
78
78
|
*
|
|
79
|
-
* ####Example:
|
|
79
|
+
* #### Example:
|
|
80
80
|
*
|
|
81
81
|
* // Make all mixed instances have `required` of true by default.
|
|
82
82
|
* mongoose.Schema.Mixed.set('required', true);
|
package/lib/schema/number.js
CHANGED
|
@@ -29,7 +29,7 @@ function SchemaNumber(key, options) {
|
|
|
29
29
|
/**
|
|
30
30
|
* Attaches a getter for all Number instances.
|
|
31
31
|
*
|
|
32
|
-
* ####Example:
|
|
32
|
+
* #### Example:
|
|
33
33
|
*
|
|
34
34
|
* // Make all numbers round down
|
|
35
35
|
* mongoose.Number.get(function(v) { return Math.floor(v); });
|
|
@@ -49,7 +49,7 @@ SchemaNumber.get = SchemaType.get;
|
|
|
49
49
|
/**
|
|
50
50
|
* Sets a default option for all Number instances.
|
|
51
51
|
*
|
|
52
|
-
* ####Example:
|
|
52
|
+
* #### Example:
|
|
53
53
|
*
|
|
54
54
|
* // Make all numbers have option `min` equal to 0.
|
|
55
55
|
* mongoose.Schema.Number.set('min', 0);
|
|
@@ -76,7 +76,7 @@ SchemaNumber._cast = castNumber;
|
|
|
76
76
|
/**
|
|
77
77
|
* Get/set the function used to cast arbitrary values to numbers.
|
|
78
78
|
*
|
|
79
|
-
* ####Example:
|
|
79
|
+
* #### Example:
|
|
80
80
|
*
|
|
81
81
|
* // Make Mongoose cast empty strings '' to 0 for paths declared as numbers
|
|
82
82
|
* const original = mongoose.Number.cast();
|
|
@@ -180,7 +180,7 @@ SchemaNumber.prototype.checkRequired = function checkRequired(value, doc) {
|
|
|
180
180
|
/**
|
|
181
181
|
* Sets a minimum number validator.
|
|
182
182
|
*
|
|
183
|
-
* ####Example:
|
|
183
|
+
* #### Example:
|
|
184
184
|
*
|
|
185
185
|
* const s = new Schema({ n: { type: Number, min: 10 })
|
|
186
186
|
* const M = db.model('M', s)
|
|
@@ -234,7 +234,7 @@ SchemaNumber.prototype.min = function(value, message) {
|
|
|
234
234
|
/**
|
|
235
235
|
* Sets a maximum number validator.
|
|
236
236
|
*
|
|
237
|
-
* ####Example:
|
|
237
|
+
* #### Example:
|
|
238
238
|
*
|
|
239
239
|
* const s = new Schema({ n: { type: Number, max: 10 })
|
|
240
240
|
* const M = db.model('M', s)
|
|
@@ -288,7 +288,7 @@ SchemaNumber.prototype.max = function(value, message) {
|
|
|
288
288
|
/**
|
|
289
289
|
* Sets a enum validator
|
|
290
290
|
*
|
|
291
|
-
* ####Example:
|
|
291
|
+
* #### Example:
|
|
292
292
|
*
|
|
293
293
|
* const s = new Schema({ n: { type: Number, enum: [1, 2, 3] });
|
|
294
294
|
* const M = db.model('M', s);
|
package/lib/schema/objectid.js
CHANGED
|
@@ -55,7 +55,7 @@ ObjectId.prototype.OptionsConstructor = SchemaObjectIdOptions;
|
|
|
55
55
|
/**
|
|
56
56
|
* Attaches a getter for all ObjectId instances
|
|
57
57
|
*
|
|
58
|
-
* ####Example:
|
|
58
|
+
* #### Example:
|
|
59
59
|
*
|
|
60
60
|
* // Always convert to string when getting an ObjectId
|
|
61
61
|
* mongoose.ObjectId.get(v => v.toString());
|
|
@@ -75,7 +75,7 @@ ObjectId.get = SchemaType.get;
|
|
|
75
75
|
/**
|
|
76
76
|
* Sets a default option for all ObjectId instances.
|
|
77
77
|
*
|
|
78
|
-
* ####Example:
|
|
78
|
+
* #### Example:
|
|
79
79
|
*
|
|
80
80
|
* // Make all object ids have option `required` equal to true.
|
|
81
81
|
* mongoose.Schema.ObjectId.set('required', true);
|
|
@@ -124,7 +124,7 @@ ObjectId._cast = castObjectId;
|
|
|
124
124
|
/**
|
|
125
125
|
* Get/set the function used to cast arbitrary values to objectids.
|
|
126
126
|
*
|
|
127
|
-
* ####Example:
|
|
127
|
+
* #### Example:
|
|
128
128
|
*
|
|
129
129
|
* // Make Mongoose only try to cast length 24 strings. By default, any 12
|
|
130
130
|
* // char string is a valid ObjectId.
|
|
@@ -171,7 +171,7 @@ ObjectId._defaultCaster = v => {
|
|
|
171
171
|
* Override the function the required validator uses to check whether a string
|
|
172
172
|
* passes the `required` check.
|
|
173
173
|
*
|
|
174
|
-
* ####Example:
|
|
174
|
+
* #### Example:
|
|
175
175
|
*
|
|
176
176
|
* // Allow empty strings to pass `required` check
|
|
177
177
|
* mongoose.Schema.Types.String.checkRequired(v => v != null);
|
package/lib/schema/string.js
CHANGED
|
@@ -58,7 +58,7 @@ SchemaString._cast = castString;
|
|
|
58
58
|
/**
|
|
59
59
|
* Get/set the function used to cast arbitrary values to strings.
|
|
60
60
|
*
|
|
61
|
-
* ####Example:
|
|
61
|
+
* #### Example:
|
|
62
62
|
*
|
|
63
63
|
* // Throw an error if you pass in an object. Normally, Mongoose allows
|
|
64
64
|
* // objects with custom `toString()` functions.
|
|
@@ -104,7 +104,7 @@ SchemaString._defaultCaster = v => {
|
|
|
104
104
|
/**
|
|
105
105
|
* Attaches a getter for all String instances.
|
|
106
106
|
*
|
|
107
|
-
* ####Example:
|
|
107
|
+
* #### Example:
|
|
108
108
|
*
|
|
109
109
|
* // Make all numbers round down
|
|
110
110
|
* mongoose.Schema.String.get(v => v.toLowerCase());
|
|
@@ -124,7 +124,7 @@ SchemaString.get = SchemaType.get;
|
|
|
124
124
|
/**
|
|
125
125
|
* Sets a default option for all String instances.
|
|
126
126
|
*
|
|
127
|
-
* ####Example:
|
|
127
|
+
* #### Example:
|
|
128
128
|
*
|
|
129
129
|
* // Make all strings have option `trim` equal to true.
|
|
130
130
|
* mongoose.Schema.String.set('trim', true);
|
|
@@ -152,7 +152,7 @@ SchemaString._checkRequired = v => (v instanceof String || typeof v === 'string'
|
|
|
152
152
|
* Override the function the required validator uses to check whether a string
|
|
153
153
|
* passes the `required` check.
|
|
154
154
|
*
|
|
155
|
-
* ####Example:
|
|
155
|
+
* #### Example:
|
|
156
156
|
*
|
|
157
157
|
* // Allow empty strings to pass `required` check
|
|
158
158
|
* mongoose.Schema.Types.String.checkRequired(v => v != null);
|
|
@@ -172,7 +172,7 @@ SchemaString.checkRequired = SchemaType.checkRequired;
|
|
|
172
172
|
/**
|
|
173
173
|
* Adds an enum validator
|
|
174
174
|
*
|
|
175
|
-
* ####Example:
|
|
175
|
+
* #### Example:
|
|
176
176
|
*
|
|
177
177
|
* const states = ['opening', 'open', 'closing', 'closed']
|
|
178
178
|
* const s = new Schema({ state: { type: String, enum: states }})
|
|
@@ -255,7 +255,7 @@ SchemaString.prototype.enum = function() {
|
|
|
255
255
|
/**
|
|
256
256
|
* Adds a lowercase [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
|
|
257
257
|
*
|
|
258
|
-
* ####Example:
|
|
258
|
+
* #### Example:
|
|
259
259
|
*
|
|
260
260
|
* const s = new Schema({ email: { type: String, lowercase: true }})
|
|
261
261
|
* const M = db.model('M', s);
|
|
@@ -265,7 +265,7 @@ SchemaString.prototype.enum = function() {
|
|
|
265
265
|
*
|
|
266
266
|
* Note that `lowercase` does **not** affect regular expression queries:
|
|
267
267
|
*
|
|
268
|
-
* ####Example:
|
|
268
|
+
* #### Example:
|
|
269
269
|
* // Still queries for documents whose `email` matches the regular
|
|
270
270
|
* // expression /SomeEmail/. Mongoose does **not** convert the RegExp
|
|
271
271
|
* // to lowercase.
|
|
@@ -293,7 +293,7 @@ SchemaString.prototype.lowercase = function(shouldApply) {
|
|
|
293
293
|
/**
|
|
294
294
|
* Adds an uppercase [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
|
|
295
295
|
*
|
|
296
|
-
* ####Example:
|
|
296
|
+
* #### Example:
|
|
297
297
|
*
|
|
298
298
|
* const s = new Schema({ caps: { type: String, uppercase: true }})
|
|
299
299
|
* const M = db.model('M', s);
|
|
@@ -303,7 +303,7 @@ SchemaString.prototype.lowercase = function(shouldApply) {
|
|
|
303
303
|
*
|
|
304
304
|
* Note that `uppercase` does **not** affect regular expression queries:
|
|
305
305
|
*
|
|
306
|
-
* ####Example:
|
|
306
|
+
* #### Example:
|
|
307
307
|
* // Mongoose does **not** convert the RegExp to uppercase.
|
|
308
308
|
* M.find({ email: /an example/ });
|
|
309
309
|
*
|
|
@@ -331,7 +331,7 @@ SchemaString.prototype.uppercase = function(shouldApply) {
|
|
|
331
331
|
*
|
|
332
332
|
* The string value will be [trimmed](https://masteringjs.io/tutorials/fundamentals/trim-string) when set.
|
|
333
333
|
*
|
|
334
|
-
* ####Example:
|
|
334
|
+
* #### Example:
|
|
335
335
|
*
|
|
336
336
|
* const s = new Schema({ name: { type: String, trim: true }});
|
|
337
337
|
* const M = db.model('M', s);
|
|
@@ -345,7 +345,7 @@ SchemaString.prototype.uppercase = function(shouldApply) {
|
|
|
345
345
|
*
|
|
346
346
|
* Note that `trim` does **not** affect regular expression queries:
|
|
347
347
|
*
|
|
348
|
-
* ####Example:
|
|
348
|
+
* #### Example:
|
|
349
349
|
* // Mongoose does **not** trim whitespace from the RegExp.
|
|
350
350
|
* M.find({ name: / some name / });
|
|
351
351
|
*
|
|
@@ -371,7 +371,7 @@ SchemaString.prototype.trim = function(shouldTrim) {
|
|
|
371
371
|
/**
|
|
372
372
|
* Sets a minimum length validator.
|
|
373
373
|
*
|
|
374
|
-
* ####Example:
|
|
374
|
+
* #### Example:
|
|
375
375
|
*
|
|
376
376
|
* const schema = new Schema({ postalCode: { type: String, minlength: 5 })
|
|
377
377
|
* const Address = db.model('Address', schema)
|
|
@@ -427,7 +427,7 @@ SchemaString.prototype.minLength = SchemaString.prototype.minlength;
|
|
|
427
427
|
/**
|
|
428
428
|
* Sets a maximum length validator.
|
|
429
429
|
*
|
|
430
|
-
* ####Example:
|
|
430
|
+
* #### Example:
|
|
431
431
|
*
|
|
432
432
|
* const schema = new Schema({ postalCode: { type: String, maxlength: 9 })
|
|
433
433
|
* const Address = db.model('Address', schema)
|
|
@@ -485,7 +485,7 @@ SchemaString.prototype.maxLength = SchemaString.prototype.maxlength;
|
|
|
485
485
|
*
|
|
486
486
|
* Any value that does not pass `regExp`.test(val) will fail validation.
|
|
487
487
|
*
|
|
488
|
-
* ####Example:
|
|
488
|
+
* #### Example:
|
|
489
489
|
*
|
|
490
490
|
* const s = new Schema({ name: { type: String, match: /^a/ }})
|
|
491
491
|
* const M = db.model('M', s)
|
package/lib/schema.js
CHANGED
|
@@ -38,7 +38,7 @@ let id = 0;
|
|
|
38
38
|
/**
|
|
39
39
|
* Schema constructor.
|
|
40
40
|
*
|
|
41
|
-
* ####Example:
|
|
41
|
+
* #### Example:
|
|
42
42
|
*
|
|
43
43
|
* const child = new Schema({ name: String });
|
|
44
44
|
* const schema = new Schema({ name: String, age: Number, children: [child] });
|
|
@@ -47,7 +47,7 @@ let id = 0;
|
|
|
47
47
|
* // setting schema options
|
|
48
48
|
* new Schema({ name: String }, { _id: false, autoIndex: false })
|
|
49
49
|
*
|
|
50
|
-
* ####Options:
|
|
50
|
+
* #### Options:
|
|
51
51
|
*
|
|
52
52
|
* - [autoIndex](/docs/guide.html#autoIndex): bool - defaults to null (which means use the connection's autoIndex option)
|
|
53
53
|
* - [autoCreate](/docs/guide.html#autoCreate): bool - defaults to null (which means use the connection's autoCreate option)
|
|
@@ -77,10 +77,10 @@ let id = 0;
|
|
|
77
77
|
* - [timestamps](/docs/guide.html#timestamps): object or boolean - defaults to `false`. If true, Mongoose adds `createdAt` and `updatedAt` properties to your schema and manages those properties for you.
|
|
78
78
|
* - [pluginTags](/docs/guide.html#pluginTags): array of strings - defaults to `undefined`. If set and plugin called with `tags` option, will only apply that plugin to schemas with a matching tag.
|
|
79
79
|
*
|
|
80
|
-
* ####Options for Nested Schemas:
|
|
80
|
+
* #### Options for Nested Schemas:
|
|
81
81
|
* - `excludeIndexes`: bool - defaults to `false`. If `true`, skip building indexes on this schema's paths.
|
|
82
82
|
*
|
|
83
|
-
* ####Note:
|
|
83
|
+
* #### Note:
|
|
84
84
|
*
|
|
85
85
|
* _When nesting schemas, (`children` in the example above), always declare the child schema first before passing it into its parent._
|
|
86
86
|
*
|
|
@@ -231,7 +231,7 @@ Object.defineProperty(Schema.prototype, 'childSchemas', {
|
|
|
231
231
|
* This property is typically only useful for plugin authors and advanced users.
|
|
232
232
|
* You do not need to interact with this property at all to use mongoose.
|
|
233
233
|
*
|
|
234
|
-
* ####Example:
|
|
234
|
+
* #### Example:
|
|
235
235
|
* const schema = new Schema({});
|
|
236
236
|
* schema.virtual('answer').get(() => 42);
|
|
237
237
|
*
|
|
@@ -253,7 +253,7 @@ Object.defineProperty(Schema.prototype, 'virtuals', {
|
|
|
253
253
|
/**
|
|
254
254
|
* The original object passed to the schema constructor
|
|
255
255
|
*
|
|
256
|
-
* ####Example:
|
|
256
|
+
* #### Example:
|
|
257
257
|
*
|
|
258
258
|
* const schema = new Schema({ a: String }).add({ b: String });
|
|
259
259
|
* schema.obj; // { a: String }
|
|
@@ -270,7 +270,7 @@ Schema.prototype.obj;
|
|
|
270
270
|
* The paths defined on this schema. The keys are the top-level paths
|
|
271
271
|
* in this schema, and the values are instances of the SchemaType class.
|
|
272
272
|
*
|
|
273
|
-
* ####Example:
|
|
273
|
+
* #### Example:
|
|
274
274
|
* const schema = new Schema({ name: String }, { _id: false });
|
|
275
275
|
* schema.paths; // { name: SchemaString { ... } }
|
|
276
276
|
*
|
|
@@ -288,7 +288,7 @@ Schema.prototype.paths;
|
|
|
288
288
|
/**
|
|
289
289
|
* Schema as a tree
|
|
290
290
|
*
|
|
291
|
-
* ####Example:
|
|
291
|
+
* #### Example:
|
|
292
292
|
* {
|
|
293
293
|
* '_id' : ObjectId
|
|
294
294
|
* , 'nested' : {
|
|
@@ -307,7 +307,7 @@ Schema.prototype.tree;
|
|
|
307
307
|
/**
|
|
308
308
|
* Returns a deep copy of the schema
|
|
309
309
|
*
|
|
310
|
-
* ####Example:
|
|
310
|
+
* #### Example:
|
|
311
311
|
*
|
|
312
312
|
* const schema = new Schema({ name: String });
|
|
313
313
|
* const clone = schema.clone();
|
|
@@ -381,7 +381,7 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
381
381
|
*
|
|
382
382
|
* This method is analagous to [Lodash's `pick()` function](https://lodash.com/docs/4.17.15#pick) for Mongoose schemas.
|
|
383
383
|
*
|
|
384
|
-
* ####Example:
|
|
384
|
+
* #### Example:
|
|
385
385
|
*
|
|
386
386
|
* const schema = Schema({ name: String, age: Number });
|
|
387
387
|
* // Creates a new schema with the same `name` path as `schema`,
|
|
@@ -472,7 +472,7 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
472
472
|
/**
|
|
473
473
|
* Adds key path / schema type pairs to this schema.
|
|
474
474
|
*
|
|
475
|
-
* ####Example:
|
|
475
|
+
* #### Example:
|
|
476
476
|
*
|
|
477
477
|
* const ToySchema = new Schema();
|
|
478
478
|
* ToySchema.add({ name: 'string', color: 'string', price: 'number' });
|
|
@@ -646,7 +646,7 @@ reserved.collection = 1;
|
|
|
646
646
|
* Sets a path (if arity 2)
|
|
647
647
|
* Gets a path (if arity 1)
|
|
648
648
|
*
|
|
649
|
-
* ####Example
|
|
649
|
+
* #### Example
|
|
650
650
|
*
|
|
651
651
|
* schema.path('name') // returns a SchemaType
|
|
652
652
|
* schema.path('name', Number) // changes the schemaType of `name` to Number
|
|
@@ -1133,7 +1133,7 @@ function createMapNestedSchemaType(schema, schemaType, path, obj, options) {
|
|
|
1133
1133
|
*
|
|
1134
1134
|
* The callback is passed the pathname and the schemaType instance.
|
|
1135
1135
|
*
|
|
1136
|
-
* ####Example:
|
|
1136
|
+
* #### Example:
|
|
1137
1137
|
*
|
|
1138
1138
|
* const userSchema = new Schema({ name: String, registeredAt: Date });
|
|
1139
1139
|
* userSchema.eachPath((pathname, schematype) => {
|
|
@@ -1162,7 +1162,7 @@ Schema.prototype.eachPath = function(fn) {
|
|
|
1162
1162
|
/**
|
|
1163
1163
|
* Returns an Array of path strings that are required by this schema.
|
|
1164
1164
|
*
|
|
1165
|
-
* ####Example:
|
|
1165
|
+
* #### Example:
|
|
1166
1166
|
* const s = new Schema({
|
|
1167
1167
|
* name: { type: String, required: true },
|
|
1168
1168
|
* age: { type: String, required: true },
|
|
@@ -1214,7 +1214,7 @@ Schema.prototype.indexedPaths = function indexedPaths() {
|
|
|
1214
1214
|
*
|
|
1215
1215
|
* Given a path, returns whether it is a real, virtual, nested, or ad-hoc/undefined path.
|
|
1216
1216
|
*
|
|
1217
|
-
* ####Example:
|
|
1217
|
+
* #### Example:
|
|
1218
1218
|
* const s = new Schema({ name: String, nested: { foo: String } });
|
|
1219
1219
|
* s.virtual('foo').get(() => 42);
|
|
1220
1220
|
* s.pathType('name'); // "real"
|
|
@@ -1371,7 +1371,7 @@ function getPositionalPath(self, path) {
|
|
|
1371
1371
|
/**
|
|
1372
1372
|
* Adds a method call to the queue.
|
|
1373
1373
|
*
|
|
1374
|
-
* ####Example:
|
|
1374
|
+
* #### Example:
|
|
1375
1375
|
*
|
|
1376
1376
|
* schema.methods.print = function() { console.log(this); };
|
|
1377
1377
|
* schema.queue('print', []); // Print the doc every one is instantiated
|
|
@@ -1392,7 +1392,7 @@ Schema.prototype.queue = function(name, args) {
|
|
|
1392
1392
|
/**
|
|
1393
1393
|
* Defines a pre hook for the model.
|
|
1394
1394
|
*
|
|
1395
|
-
* ####Example
|
|
1395
|
+
* #### Example
|
|
1396
1396
|
*
|
|
1397
1397
|
* const toySchema = new Schema({ name: String, created: Date });
|
|
1398
1398
|
*
|
|
@@ -1514,7 +1514,7 @@ Schema.prototype.post = function(name) {
|
|
|
1514
1514
|
/**
|
|
1515
1515
|
* Registers a plugin for this schema.
|
|
1516
1516
|
*
|
|
1517
|
-
* ####Example:
|
|
1517
|
+
* #### Example:
|
|
1518
1518
|
*
|
|
1519
1519
|
* const s = new Schema({ name: String });
|
|
1520
1520
|
* s.plugin(schema => console.log(schema.path('name').path));
|
|
@@ -1548,7 +1548,7 @@ Schema.prototype.plugin = function(fn, opts) {
|
|
|
1548
1548
|
/**
|
|
1549
1549
|
* Adds an instance method to documents constructed from Models compiled from this schema.
|
|
1550
1550
|
*
|
|
1551
|
-
* ####Example
|
|
1551
|
+
* #### Example
|
|
1552
1552
|
*
|
|
1553
1553
|
* const schema = kittySchema = new Schema(..);
|
|
1554
1554
|
*
|
|
@@ -1595,7 +1595,7 @@ Schema.prototype.method = function(name, fn, options) {
|
|
|
1595
1595
|
/**
|
|
1596
1596
|
* Adds static "class" methods to Models compiled from this schema.
|
|
1597
1597
|
*
|
|
1598
|
-
* ####Example
|
|
1598
|
+
* #### Example
|
|
1599
1599
|
*
|
|
1600
1600
|
* const schema = new Schema(..);
|
|
1601
1601
|
* // Equivalent to `schema.statics.findByName = function(name) {}`;
|
|
@@ -1628,7 +1628,7 @@ Schema.prototype.static = function(name, fn) {
|
|
|
1628
1628
|
/**
|
|
1629
1629
|
* Defines an index (most likely compound) for this schema.
|
|
1630
1630
|
*
|
|
1631
|
-
* ####Example
|
|
1631
|
+
* #### Example
|
|
1632
1632
|
*
|
|
1633
1633
|
* schema.index({ first: 1, last: -1 })
|
|
1634
1634
|
*
|
|
@@ -1653,7 +1653,7 @@ Schema.prototype.index = function(fields, options) {
|
|
|
1653
1653
|
/**
|
|
1654
1654
|
* Sets a schema option.
|
|
1655
1655
|
*
|
|
1656
|
-
* ####Example
|
|
1656
|
+
* #### Example
|
|
1657
1657
|
*
|
|
1658
1658
|
* schema.set('strict'); // 'true' by default
|
|
1659
1659
|
* schema.set('strict', false); // Sets 'strict' to false
|
|
@@ -1702,7 +1702,7 @@ Schema.prototype.set = function(key, value, _tags) {
|
|
|
1702
1702
|
/**
|
|
1703
1703
|
* Gets a schema option.
|
|
1704
1704
|
*
|
|
1705
|
-
* ####Example:
|
|
1705
|
+
* #### Example:
|
|
1706
1706
|
*
|
|
1707
1707
|
* schema.get('strict'); // true
|
|
1708
1708
|
* schema.set('strict', false);
|
|
@@ -1740,7 +1740,7 @@ Object.defineProperty(Schema, 'indexTypes', {
|
|
|
1740
1740
|
* Returns a list of indexes that this schema declares, via `schema.index()` or by `index: true` in a path's options.
|
|
1741
1741
|
* Indexes are expressed as an array `[spec, options]`.
|
|
1742
1742
|
*
|
|
1743
|
-
* ####Example:
|
|
1743
|
+
* #### Example:
|
|
1744
1744
|
*
|
|
1745
1745
|
* const userSchema = new Schema({
|
|
1746
1746
|
* email: { type: String, required: true, unique: true },
|
|
@@ -1902,7 +1902,7 @@ Schema.prototype.virtualpath = function(name) {
|
|
|
1902
1902
|
/**
|
|
1903
1903
|
* Removes the given `path` (or [`paths`]).
|
|
1904
1904
|
*
|
|
1905
|
-
* ####Example:
|
|
1905
|
+
* #### Example:
|
|
1906
1906
|
*
|
|
1907
1907
|
* const schema = new Schema({ name: String, age: Number });
|
|
1908
1908
|
* schema.remove('name');
|
|
@@ -1969,7 +1969,7 @@ function _deletePath(schema, name) {
|
|
|
1969
1969
|
* [statics](/docs/guide.html#statics), and
|
|
1970
1970
|
* [methods](/docs/guide.html#methods).
|
|
1971
1971
|
*
|
|
1972
|
-
* ####Example:
|
|
1972
|
+
* #### Example:
|
|
1973
1973
|
*
|
|
1974
1974
|
* ```javascript
|
|
1975
1975
|
* const md5 = require('md5');
|
|
@@ -2232,12 +2232,12 @@ module.exports = exports = Schema;
|
|
|
2232
2232
|
/**
|
|
2233
2233
|
* The various built-in Mongoose Schema Types.
|
|
2234
2234
|
*
|
|
2235
|
-
* ####Example:
|
|
2235
|
+
* #### Example:
|
|
2236
2236
|
*
|
|
2237
2237
|
* const mongoose = require('mongoose');
|
|
2238
2238
|
* const ObjectId = mongoose.Schema.Types.ObjectId;
|
|
2239
2239
|
*
|
|
2240
|
-
* ####Types:
|
|
2240
|
+
* #### Types:
|
|
2241
2241
|
*
|
|
2242
2242
|
* - [String](/docs/schematypes.html#strings)
|
|
2243
2243
|
* - [Number](/docs/schematypes.html#numbers)
|