mongoose 6.4.3 → 6.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aggregate.js +3 -2
- package/lib/connection.js +9 -9
- package/lib/cursor/AggregationCursor.js +3 -2
- package/lib/cursor/QueryCursor.js +5 -4
- package/lib/document.js +43 -15
- package/lib/error/index.js +12 -12
- package/lib/error/messages.js +2 -2
- package/lib/helpers/query/castUpdate.js +4 -4
- package/lib/index.js +5 -2
- package/lib/model.js +22 -21
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +3 -3
- package/lib/options/SchemaDocumentArrayOptions.js +2 -2
- package/lib/options/SchemaMapOptions.js +1 -1
- package/lib/options/SchemaNumberOptions.js +4 -4
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +8 -8
- package/lib/options/SchemaSubdocumentOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +14 -14
- package/lib/options/VirtualOptions.js +11 -11
- package/lib/query.js +74 -71
- package/lib/schema/SubdocumentPath.js +10 -6
- package/lib/schema/array.js +3 -3
- package/lib/schema/boolean.js +5 -5
- package/lib/schema/buffer.js +2 -2
- package/lib/schema/date.js +2 -2
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +12 -8
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +2 -2
- package/lib/schema/objectid.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema.js +69 -34
- package/lib/schematype.js +7 -9
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/types/buffer.js +8 -4
- package/lib/types/decimal128.js +1 -1
- package/lib/types/map.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +1 -1
- package/lib/virtualtype.js +5 -5
- package/package.json +5 -5
- package/types/models.d.ts +2 -1
- package/types/query.d.ts +6 -1
package/lib/aggregate.js
CHANGED
|
@@ -481,7 +481,8 @@ Aggregate.prototype.sortByCount = function(arg) {
|
|
|
481
481
|
*
|
|
482
482
|
* @see $lookup https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/#pipe._S_lookup
|
|
483
483
|
* @param {Object} options to $lookup as described in the above link
|
|
484
|
-
* @return {Aggregate}
|
|
484
|
+
* @return {Aggregate}
|
|
485
|
+
* @api public
|
|
485
486
|
*/
|
|
486
487
|
|
|
487
488
|
Aggregate.prototype.lookup = function(options) {
|
|
@@ -1051,7 +1052,7 @@ Aggregate.prototype.catch = function(reject) {
|
|
|
1051
1052
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
1052
1053
|
* will call it for you.
|
|
1053
1054
|
*
|
|
1054
|
-
* #### Example
|
|
1055
|
+
* #### Example:
|
|
1055
1056
|
*
|
|
1056
1057
|
* const agg = Model.aggregate([{ $match: { age: { $gte: 25 } } }]);
|
|
1057
1058
|
* for await (const doc of agg) {
|
package/lib/connection.js
CHANGED
|
@@ -93,7 +93,7 @@ Connection.prototype.__proto__ = EventEmitter.prototype;
|
|
|
93
93
|
*
|
|
94
94
|
* Each state change emits its associated event name.
|
|
95
95
|
*
|
|
96
|
-
* #### Example
|
|
96
|
+
* #### Example:
|
|
97
97
|
*
|
|
98
98
|
* conn.on('connected', callback);
|
|
99
99
|
* conn.on('disconnected', callback);
|
|
@@ -193,7 +193,7 @@ Connection.prototype.collections;
|
|
|
193
193
|
/**
|
|
194
194
|
* The name of the database this connection points to.
|
|
195
195
|
*
|
|
196
|
-
* #### Example
|
|
196
|
+
* #### Example:
|
|
197
197
|
*
|
|
198
198
|
* mongoose.createConnection('mongodb://localhost:27017/mydb').name; // "mydb"
|
|
199
199
|
*
|
|
@@ -210,7 +210,7 @@ Connection.prototype.name;
|
|
|
210
210
|
* a map from model names to models. Contains all models that have been
|
|
211
211
|
* added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
|
|
212
212
|
*
|
|
213
|
-
* #### Example
|
|
213
|
+
* #### Example:
|
|
214
214
|
*
|
|
215
215
|
* const conn = mongoose.createConnection();
|
|
216
216
|
* const Test = conn.model('Test', mongoose.Schema({ name: String }));
|
|
@@ -230,7 +230,7 @@ Connection.prototype.models;
|
|
|
230
230
|
* A number identifier for this connection. Used for debugging when
|
|
231
231
|
* you have [multiple connections](/docs/connections.html#multiple_connections).
|
|
232
232
|
*
|
|
233
|
-
* #### Example
|
|
233
|
+
* #### Example:
|
|
234
234
|
*
|
|
235
235
|
* // The default connection has `id = 0`
|
|
236
236
|
* mongoose.connection.id; // 0
|
|
@@ -274,7 +274,7 @@ Object.defineProperty(Connection.prototype, 'plugins', {
|
|
|
274
274
|
* The host name portion of the URI. If multiple hosts, such as a replica set,
|
|
275
275
|
* this will contain the first host name in the URI
|
|
276
276
|
*
|
|
277
|
-
* #### Example
|
|
277
|
+
* #### Example:
|
|
278
278
|
*
|
|
279
279
|
* mongoose.createConnection('mongodb://localhost:27017/mydb').host; // "localhost"
|
|
280
280
|
*
|
|
@@ -294,7 +294,7 @@ Object.defineProperty(Connection.prototype, 'host', {
|
|
|
294
294
|
* The port portion of the URI. If multiple hosts, such as a replica set,
|
|
295
295
|
* this will contain the port from the first host name in the URI.
|
|
296
296
|
*
|
|
297
|
-
* #### Example
|
|
297
|
+
* #### Example:
|
|
298
298
|
*
|
|
299
299
|
* mongoose.createConnection('mongodb://localhost:27017/mydb').port; // 27017
|
|
300
300
|
*
|
|
@@ -313,7 +313,7 @@ Object.defineProperty(Connection.prototype, 'port', {
|
|
|
313
313
|
/**
|
|
314
314
|
* The username specified in the URI
|
|
315
315
|
*
|
|
316
|
-
* #### Example
|
|
316
|
+
* #### Example:
|
|
317
317
|
*
|
|
318
318
|
* mongoose.createConnection('mongodb://val:psw@localhost:27017/mydb').user; // "val"
|
|
319
319
|
*
|
|
@@ -332,7 +332,7 @@ Object.defineProperty(Connection.prototype, 'user', {
|
|
|
332
332
|
/**
|
|
333
333
|
* The password specified in the URI
|
|
334
334
|
*
|
|
335
|
-
* #### Example
|
|
335
|
+
* #### Example:
|
|
336
336
|
*
|
|
337
337
|
* mongoose.createConnection('mongodb://val:psw@localhost:27017/mydb').pass; // "psw"
|
|
338
338
|
*
|
|
@@ -1452,7 +1452,7 @@ Connection.prototype.setClient = function setClient(client) {
|
|
|
1452
1452
|
*
|
|
1453
1453
|
* @param {Object} options
|
|
1454
1454
|
* @param {Boolean} options.continueOnError `false` by default. If set to `true`, mongoose will not throw an error if one model syncing failed, and will return an object where the keys are the names of the models, and the values are the results/errors for each model.
|
|
1455
|
-
* @
|
|
1455
|
+
* @return {Promise} Returns a Promise, when the Promise resolves the value is a list of the dropped indexes.
|
|
1456
1456
|
*/
|
|
1457
1457
|
Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
1458
1458
|
const result = {};
|
|
@@ -107,7 +107,7 @@ if (Symbol.asyncIterator != null) {
|
|
|
107
107
|
* Registers a transform function which subsequently maps documents retrieved
|
|
108
108
|
* via the streams interface or `.next()`
|
|
109
109
|
*
|
|
110
|
-
* #### Example
|
|
110
|
+
* #### Example:
|
|
111
111
|
*
|
|
112
112
|
* // Map documents returned by `data` events
|
|
113
113
|
* Thing.
|
|
@@ -132,6 +132,7 @@ if (Symbol.asyncIterator != null) {
|
|
|
132
132
|
*
|
|
133
133
|
* @param {Function} fn
|
|
134
134
|
* @return {AggregationCursor}
|
|
135
|
+
* @memberOf AggregationCursor
|
|
135
136
|
* @api public
|
|
136
137
|
* @method map
|
|
137
138
|
*/
|
|
@@ -226,7 +227,7 @@ AggregationCursor.prototype.eachAsync = function(fn, opts, callback) {
|
|
|
226
227
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
227
228
|
* will call it for you.
|
|
228
229
|
*
|
|
229
|
-
* #### Example
|
|
230
|
+
* #### Example:
|
|
230
231
|
*
|
|
231
232
|
* // Async iterator without explicitly calling `cursor()`. Mongoose still
|
|
232
233
|
* // creates an AggregationCursor instance internally.
|
|
@@ -112,7 +112,7 @@ QueryCursor.prototype._read = function() {
|
|
|
112
112
|
* Registers a transform function which subsequently maps documents retrieved
|
|
113
113
|
* via the streams interface or `.next()`
|
|
114
114
|
*
|
|
115
|
-
* #### Example
|
|
115
|
+
* #### Example:
|
|
116
116
|
*
|
|
117
117
|
* // Map documents returned by `data` events
|
|
118
118
|
* Thing.
|
|
@@ -137,6 +137,7 @@ QueryCursor.prototype._read = function() {
|
|
|
137
137
|
*
|
|
138
138
|
* @param {Function} fn
|
|
139
139
|
* @return {QueryCursor}
|
|
140
|
+
* @memberOf QueryCursor
|
|
140
141
|
* @api public
|
|
141
142
|
* @method map
|
|
142
143
|
*/
|
|
@@ -211,7 +212,7 @@ QueryCursor.prototype.next = function(callback) {
|
|
|
211
212
|
* will wait for the promise to resolve before iterating on to the next one.
|
|
212
213
|
* Returns a promise that resolves when done.
|
|
213
214
|
*
|
|
214
|
-
* #### Example
|
|
215
|
+
* #### Example:
|
|
215
216
|
*
|
|
216
217
|
* // Iterate over documents asynchronously
|
|
217
218
|
* Thing.
|
|
@@ -300,7 +301,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
|
|
|
300
301
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
301
302
|
* will call it for you.
|
|
302
303
|
*
|
|
303
|
-
* #### Example
|
|
304
|
+
* #### Example:
|
|
304
305
|
*
|
|
305
306
|
* // Works without using `cursor()`
|
|
306
307
|
* for await (const doc of Model.find([{ $sort: { name: 1 } }])) {
|
|
@@ -320,7 +321,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
|
|
|
320
321
|
* support async iterators.
|
|
321
322
|
*
|
|
322
323
|
* @method Symbol.asyncIterator
|
|
323
|
-
* @memberOf
|
|
324
|
+
* @memberOf QueryCursor
|
|
324
325
|
* @instance
|
|
325
326
|
* @api public
|
|
326
327
|
*/
|
package/lib/document.js
CHANGED
|
@@ -300,7 +300,35 @@ Object.defineProperty(Document.prototype, '$locals', {
|
|
|
300
300
|
|
|
301
301
|
|
|
302
302
|
/**
|
|
303
|
-
* Boolean flag specifying if the document is new.
|
|
303
|
+
* Boolean flag specifying if the document is new. If you create a document
|
|
304
|
+
* using `new`, this document will be considered "new". `$isNew` is how
|
|
305
|
+
* Mongoose determines whether `save()` should use `insertOne()` to create
|
|
306
|
+
* a new document or `updateOne()` to update an existing document.
|
|
307
|
+
*
|
|
308
|
+
* #### Example:
|
|
309
|
+
* const user = new User({ name: 'John Smith' });
|
|
310
|
+
* user.$isNew; // true
|
|
311
|
+
*
|
|
312
|
+
* await user.save(); // Sends an `insertOne` to MongoDB
|
|
313
|
+
*
|
|
314
|
+
* On the other hand, if you load an existing document from the database
|
|
315
|
+
* using `findOne()` or another [query operation](/docs/queries.html),
|
|
316
|
+
* `$isNew` will be false.
|
|
317
|
+
*
|
|
318
|
+
* #### Example:
|
|
319
|
+
* const user = await User.findOne({ name: 'John Smith' });
|
|
320
|
+
* user.$isNew; // false
|
|
321
|
+
*
|
|
322
|
+
* For subdocuments, `$isNew` is true if either the parent has `$isNew` set,
|
|
323
|
+
* or if you create a new subdocument.
|
|
324
|
+
*
|
|
325
|
+
* #### Example:
|
|
326
|
+
* // Assume `Group` has a document array `users`
|
|
327
|
+
* const group = await Group.findOne();
|
|
328
|
+
* group.users[0].$isNew; // false
|
|
329
|
+
*
|
|
330
|
+
* group.users.push({ name: 'John Smith' });
|
|
331
|
+
* group.users[1].$isNew; // true
|
|
304
332
|
*
|
|
305
333
|
* @api public
|
|
306
334
|
* @property $isNew
|
|
@@ -311,7 +339,7 @@ Object.defineProperty(Document.prototype, '$locals', {
|
|
|
311
339
|
Document.prototype.$isNew;
|
|
312
340
|
|
|
313
341
|
/**
|
|
314
|
-
*
|
|
342
|
+
* Legacy alias for `$isNew`.
|
|
315
343
|
*
|
|
316
344
|
* @api public
|
|
317
345
|
* @property isNew
|
|
@@ -1722,7 +1750,7 @@ Document.prototype.$__setValue = function(path, val) {
|
|
|
1722
1750
|
/**
|
|
1723
1751
|
* Returns the value of a path.
|
|
1724
1752
|
*
|
|
1725
|
-
* #### Example
|
|
1753
|
+
* #### Example:
|
|
1726
1754
|
*
|
|
1727
1755
|
* // path
|
|
1728
1756
|
* doc.get('age') // 47
|
|
@@ -1895,7 +1923,7 @@ Document.prototype.$ignore = function(path) {
|
|
|
1895
1923
|
* A path `a` may be in `modifiedPaths()` but not in `directModifiedPaths()`
|
|
1896
1924
|
* because a child of `a` was directly modified.
|
|
1897
1925
|
*
|
|
1898
|
-
* #### Example
|
|
1926
|
+
* #### Example:
|
|
1899
1927
|
* const schema = new Schema({ foo: String, nested: { bar: String } });
|
|
1900
1928
|
* const Model = mongoose.model('Test', schema);
|
|
1901
1929
|
* await Model.create({ foo: 'original', nested: { bar: 'original' } });
|
|
@@ -2051,7 +2079,7 @@ Document.prototype[documentModifiedPaths] = Document.prototype.modifiedPaths;
|
|
|
2051
2079
|
*
|
|
2052
2080
|
* If `path` is given, checks if a path or any full path containing `path` as part of its path chain has been modified.
|
|
2053
2081
|
*
|
|
2054
|
-
* #### Example
|
|
2082
|
+
* #### Example:
|
|
2055
2083
|
*
|
|
2056
2084
|
* doc.set('documents.0.title', 'changed');
|
|
2057
2085
|
* doc.isModified() // true
|
|
@@ -2097,7 +2125,7 @@ Document.prototype[documentIsModified] = Document.prototype.isModified;
|
|
|
2097
2125
|
/**
|
|
2098
2126
|
* Checks if a path is set to its default.
|
|
2099
2127
|
*
|
|
2100
|
-
* #### Example
|
|
2128
|
+
* #### Example:
|
|
2101
2129
|
*
|
|
2102
2130
|
* MyModel = mongoose.model('test', { name: { type: String, default: 'Val '} });
|
|
2103
2131
|
* const m = new MyModel();
|
|
@@ -2161,13 +2189,13 @@ Document.prototype.$isDeleted = function(val) {
|
|
|
2161
2189
|
/**
|
|
2162
2190
|
* Returns true if `path` was directly set and modified, else false.
|
|
2163
2191
|
*
|
|
2164
|
-
* #### Example
|
|
2192
|
+
* #### Example:
|
|
2165
2193
|
*
|
|
2166
2194
|
* doc.set('documents.0.title', 'changed');
|
|
2167
2195
|
* doc.isDirectModified('documents.0.title') // true
|
|
2168
2196
|
* doc.isDirectModified('documents') // false
|
|
2169
2197
|
*
|
|
2170
|
-
* @param {String|
|
|
2198
|
+
* @param {String|String[]} path
|
|
2171
2199
|
* @return {Boolean}
|
|
2172
2200
|
* @api public
|
|
2173
2201
|
*/
|
|
@@ -2217,13 +2245,13 @@ Document.prototype.isInit = function(path) {
|
|
|
2217
2245
|
/**
|
|
2218
2246
|
* Checks if `path` was selected in the source query which initialized this document.
|
|
2219
2247
|
*
|
|
2220
|
-
* #### Example
|
|
2248
|
+
* #### Example:
|
|
2221
2249
|
*
|
|
2222
2250
|
* const doc = await Thing.findOne().select('name');
|
|
2223
2251
|
* doc.isSelected('name') // true
|
|
2224
2252
|
* doc.isSelected('age') // false
|
|
2225
2253
|
*
|
|
2226
|
-
* @param {String|
|
|
2254
|
+
* @param {String|String[]} path
|
|
2227
2255
|
* @return {Boolean}
|
|
2228
2256
|
* @api public
|
|
2229
2257
|
*/
|
|
@@ -2298,7 +2326,7 @@ Document.prototype.$__isSelected = Document.prototype.isSelected;
|
|
|
2298
2326
|
* Checks if `path` was explicitly selected. If no projection, always returns
|
|
2299
2327
|
* true.
|
|
2300
2328
|
*
|
|
2301
|
-
* #### Example
|
|
2329
|
+
* #### Example:
|
|
2302
2330
|
*
|
|
2303
2331
|
* Thing.findOne().select('nested.name').exec(function (err, doc) {
|
|
2304
2332
|
* doc.isDirectSelected('nested.name') // true
|
|
@@ -3110,7 +3138,7 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
|
|
|
3110
3138
|
/**
|
|
3111
3139
|
* Checks if a path is invalid
|
|
3112
3140
|
*
|
|
3113
|
-
* @param {String|
|
|
3141
|
+
* @param {String|String[]} path the field to check
|
|
3114
3142
|
* @method $isValid
|
|
3115
3143
|
* @memberOf Document
|
|
3116
3144
|
* @instance
|
|
@@ -3640,7 +3668,7 @@ Document.prototype.$toObject = function(options, json) {
|
|
|
3640
3668
|
*
|
|
3641
3669
|
* schema.set('toObject', { virtuals: true })
|
|
3642
3670
|
*
|
|
3643
|
-
* #### Transform
|
|
3671
|
+
* #### Transform:
|
|
3644
3672
|
*
|
|
3645
3673
|
* We may need to perform a transformation of the resulting object based on some criteria, say to remove some sensitive information or return a custom object. In this case we set the optional `transform` function.
|
|
3646
3674
|
*
|
|
@@ -3652,7 +3680,7 @@ Document.prototype.$toObject = function(options, json) {
|
|
|
3652
3680
|
* - `ret` The plain object representation which has been converted
|
|
3653
3681
|
* - `options` The options in use (either schema options or the options passed inline)
|
|
3654
3682
|
*
|
|
3655
|
-
* #### Example
|
|
3683
|
+
* #### Example:
|
|
3656
3684
|
*
|
|
3657
3685
|
* // specify the transform schema option
|
|
3658
3686
|
* if (!schema.options.toObject) schema.options.toObject = {};
|
|
@@ -4342,7 +4370,7 @@ Document.prototype.$populated = Document.prototype.populated;
|
|
|
4342
4370
|
* doc.$assertPopulated('other path'); // throws an error
|
|
4343
4371
|
*
|
|
4344
4372
|
*
|
|
4345
|
-
* @param {String|
|
|
4373
|
+
* @param {String|String[]} path
|
|
4346
4374
|
* @return {Document} this
|
|
4347
4375
|
* @memberOf Document
|
|
4348
4376
|
* @method $assertPopulated
|
package/lib/error/index.js
CHANGED
|
@@ -56,7 +56,7 @@ module.exports = exports = MongooseError;
|
|
|
56
56
|
* @see Error.messages #error_messages_MongooseError-messages
|
|
57
57
|
* @api public
|
|
58
58
|
* @memberOf Error
|
|
59
|
-
* @static
|
|
59
|
+
* @static
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
62
|
MongooseError.messages = require('./messages');
|
|
@@ -73,7 +73,7 @@ MongooseError.Messages = MongooseError.messages;
|
|
|
73
73
|
*
|
|
74
74
|
* @api public
|
|
75
75
|
* @memberOf Error
|
|
76
|
-
* @static
|
|
76
|
+
* @static
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
79
|
MongooseError.DocumentNotFoundError = require('./notFound');
|
|
@@ -84,7 +84,7 @@ MongooseError.DocumentNotFoundError = require('./notFound');
|
|
|
84
84
|
*
|
|
85
85
|
* @api public
|
|
86
86
|
* @memberOf Error
|
|
87
|
-
* @static
|
|
87
|
+
* @static
|
|
88
88
|
*/
|
|
89
89
|
|
|
90
90
|
MongooseError.CastError = require('./cast');
|
|
@@ -96,7 +96,7 @@ MongooseError.CastError = require('./cast');
|
|
|
96
96
|
*
|
|
97
97
|
* @api public
|
|
98
98
|
* @memberOf Error
|
|
99
|
-
* @static
|
|
99
|
+
* @static
|
|
100
100
|
*/
|
|
101
101
|
|
|
102
102
|
MongooseError.ValidationError = require('./validation');
|
|
@@ -131,7 +131,7 @@ MongooseError.ValidationError = require('./validation');
|
|
|
131
131
|
*
|
|
132
132
|
* @api public
|
|
133
133
|
* @memberOf Error
|
|
134
|
-
* @static
|
|
134
|
+
* @static
|
|
135
135
|
*/
|
|
136
136
|
|
|
137
137
|
MongooseError.ValidatorError = require('./validator');
|
|
@@ -143,7 +143,7 @@ MongooseError.ValidatorError = require('./validator');
|
|
|
143
143
|
*
|
|
144
144
|
* @api public
|
|
145
145
|
* @memberOf Error
|
|
146
|
-
* @static
|
|
146
|
+
* @static
|
|
147
147
|
*/
|
|
148
148
|
|
|
149
149
|
MongooseError.VersionError = require('./version');
|
|
@@ -155,7 +155,7 @@ MongooseError.VersionError = require('./version');
|
|
|
155
155
|
*
|
|
156
156
|
* @api public
|
|
157
157
|
* @memberOf Error
|
|
158
|
-
* @static
|
|
158
|
+
* @static
|
|
159
159
|
*/
|
|
160
160
|
|
|
161
161
|
MongooseError.ParallelSaveError = require('./parallelSave');
|
|
@@ -166,7 +166,7 @@ MongooseError.ParallelSaveError = require('./parallelSave');
|
|
|
166
166
|
*
|
|
167
167
|
* @api public
|
|
168
168
|
* @memberOf Error
|
|
169
|
-
* @static
|
|
169
|
+
* @static
|
|
170
170
|
*/
|
|
171
171
|
|
|
172
172
|
MongooseError.OverwriteModelError = require('./overwriteModel');
|
|
@@ -176,7 +176,7 @@ MongooseError.OverwriteModelError = require('./overwriteModel');
|
|
|
176
176
|
*
|
|
177
177
|
* @api public
|
|
178
178
|
* @memberOf Error
|
|
179
|
-
* @static
|
|
179
|
+
* @static
|
|
180
180
|
*/
|
|
181
181
|
|
|
182
182
|
MongooseError.MissingSchemaError = require('./missingSchema');
|
|
@@ -187,7 +187,7 @@ MongooseError.MissingSchemaError = require('./missingSchema');
|
|
|
187
187
|
*
|
|
188
188
|
* @api public
|
|
189
189
|
* @memberOf Error
|
|
190
|
-
* @static
|
|
190
|
+
* @static
|
|
191
191
|
*/
|
|
192
192
|
|
|
193
193
|
MongooseError.MongooseServerSelectionError = require('./serverSelection');
|
|
@@ -198,7 +198,7 @@ MongooseError.MongooseServerSelectionError = require('./serverSelection');
|
|
|
198
198
|
*
|
|
199
199
|
* @api public
|
|
200
200
|
* @memberOf Error
|
|
201
|
-
* @static
|
|
201
|
+
* @static
|
|
202
202
|
*/
|
|
203
203
|
|
|
204
204
|
MongooseError.DivergentArrayError = require('./divergentArray');
|
|
@@ -210,7 +210,7 @@ MongooseError.DivergentArrayError = require('./divergentArray');
|
|
|
210
210
|
*
|
|
211
211
|
* @api public
|
|
212
212
|
* @memberOf Error
|
|
213
|
-
* @static
|
|
213
|
+
* @static
|
|
214
214
|
*/
|
|
215
215
|
|
|
216
216
|
MongooseError.StrictModeError = require('./strict');
|
package/lib/error/messages.js
CHANGED
|
@@ -155,12 +155,12 @@ function castPipelineOperator(op, val) {
|
|
|
155
155
|
* according to its schema.
|
|
156
156
|
*
|
|
157
157
|
* @param {Schema} schema
|
|
158
|
-
* @param {Object} obj
|
|
159
|
-
* @param {String} op
|
|
158
|
+
* @param {Object} obj part of a query
|
|
159
|
+
* @param {String} op the atomic operator ($pull, $set, etc)
|
|
160
160
|
* @param {Object} options
|
|
161
161
|
* @param {Boolean|String} [options.strict]
|
|
162
162
|
* @param {Query} context
|
|
163
|
-
* @param {String} pref
|
|
163
|
+
* @param {String} pref path prefix (internal only)
|
|
164
164
|
* @return {Bool} true if this path has keys to update
|
|
165
165
|
* @api private
|
|
166
166
|
*/
|
|
@@ -451,7 +451,7 @@ const overwriteOps = {
|
|
|
451
451
|
*
|
|
452
452
|
* @param {SchemaType} schema
|
|
453
453
|
* @param {Object} val
|
|
454
|
-
* @param {String} op
|
|
454
|
+
* @param {String} op the atomic operator ($pull, $set, etc)
|
|
455
455
|
* @param {String} $conditional
|
|
456
456
|
* @param {Query} context
|
|
457
457
|
* @api private
|
package/lib/index.js
CHANGED
|
@@ -172,6 +172,7 @@ Mongoose.prototype.setDriver = function setDriver(driver) {
|
|
|
172
172
|
|
|
173
173
|
const Connection = driver.getConnection();
|
|
174
174
|
_mongoose.connections = [new Connection(_mongoose)];
|
|
175
|
+
_mongoose.connections[0].models = _mongoose.models;
|
|
175
176
|
|
|
176
177
|
return _mongoose;
|
|
177
178
|
};
|
|
@@ -761,6 +762,8 @@ Mongoose.prototype.Aggregate = Aggregate;
|
|
|
761
762
|
/**
|
|
762
763
|
* The Mongoose Collection constructor
|
|
763
764
|
*
|
|
765
|
+
* @memberOf Mongoose
|
|
766
|
+
* @instance
|
|
764
767
|
* @method Collection
|
|
765
768
|
* @api public
|
|
766
769
|
*/
|
|
@@ -799,7 +802,7 @@ Object.defineProperty(Mongoose.prototype, 'Connection', {
|
|
|
799
802
|
/**
|
|
800
803
|
* The Mongoose version
|
|
801
804
|
*
|
|
802
|
-
* #### Example
|
|
805
|
+
* #### Example:
|
|
803
806
|
*
|
|
804
807
|
* console.log(mongoose.version); // '5.x.x'
|
|
805
808
|
*
|
|
@@ -1044,7 +1047,7 @@ Mongoose.prototype.isObjectIdOrHexString = function(v) {
|
|
|
1044
1047
|
*
|
|
1045
1048
|
* @param {Object} options
|
|
1046
1049
|
* @param {Boolean} options.continueOnError `false` by default. If set to `true`, mongoose will not throw an error if one model syncing failed, and will return an object where the keys are the names of the models, and the values are the results/errors for each model.
|
|
1047
|
-
* @
|
|
1050
|
+
* @return {Promise} Returns a Promise, when the Promise resolves the value is a list of the dropped indexes.
|
|
1048
1051
|
*/
|
|
1049
1052
|
Mongoose.prototype.syncIndexes = function(options) {
|
|
1050
1053
|
const _mongoose = this instanceof Mongoose ? this : mongoose;
|
package/lib/model.js
CHANGED
|
@@ -212,7 +212,7 @@ Model.prototype.baseModelName;
|
|
|
212
212
|
* @api public
|
|
213
213
|
* @fires error whenever any query or model function errors
|
|
214
214
|
* @memberOf Model
|
|
215
|
-
* @static
|
|
215
|
+
* @static
|
|
216
216
|
*/
|
|
217
217
|
|
|
218
218
|
Model.events;
|
|
@@ -899,6 +899,7 @@ Model.prototype.$__version = function(where, delta) {
|
|
|
899
899
|
* })
|
|
900
900
|
*
|
|
901
901
|
* @see versionKeys https://mongoosejs.com/docs/guide.html#versionKey
|
|
902
|
+
* @memberOf Model
|
|
902
903
|
* @api public
|
|
903
904
|
*/
|
|
904
905
|
|
|
@@ -1453,7 +1454,7 @@ Model.createCollection = function createCollection(options, callback) {
|
|
|
1453
1454
|
* @param {Object} [options] options to pass to `ensureIndexes()`
|
|
1454
1455
|
* @param {Boolean} [options.background=null] if specified, overrides each index's `background` property
|
|
1455
1456
|
* @param {Function} [callback] optional callback
|
|
1456
|
-
* @return {Promise|undefined} Returns `undefined` if callback is specified, returns a promise if no callback.
|
|
1457
|
+
* @return {Promise|undefined} Returns `undefined` if callback is specified, returns a promise if no callback, when the Promise resolves the value is a list of the dropped indexes.
|
|
1457
1458
|
* @api public
|
|
1458
1459
|
*/
|
|
1459
1460
|
|
|
@@ -1821,7 +1822,7 @@ function _ensureIndexes(model, options, callback) {
|
|
|
1821
1822
|
* Schema the model uses.
|
|
1822
1823
|
*
|
|
1823
1824
|
* @property schema
|
|
1824
|
-
* @
|
|
1825
|
+
* @static
|
|
1825
1826
|
* @api public
|
|
1826
1827
|
* @memberOf Model
|
|
1827
1828
|
*/
|
|
@@ -2128,7 +2129,7 @@ Model.deleteMany = function deleteMany(conditions, options, callback) {
|
|
|
2128
2129
|
* await MyModel.find({ name: /john/i }, null, { skip: 10 }).exec();
|
|
2129
2130
|
*
|
|
2130
2131
|
* @param {Object|ObjectId} filter
|
|
2131
|
-
* @param {Object|String|
|
|
2132
|
+
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api.html#query_Query-select)
|
|
2132
2133
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
|
|
2133
2134
|
* @param {Function} [callback]
|
|
2134
2135
|
* @return {Query}
|
|
@@ -2191,7 +2192,7 @@ Model.find = function find(conditions, projection, options, callback) {
|
|
|
2191
2192
|
* await Adventure.findById(id, 'name length').exec();
|
|
2192
2193
|
*
|
|
2193
2194
|
* @param {Any} id value of `_id` to query by
|
|
2194
|
-
* @param {Object|String|
|
|
2195
|
+
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2195
2196
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
|
|
2196
2197
|
* @param {Function} [callback]
|
|
2197
2198
|
* @return {Query}
|
|
@@ -2234,7 +2235,7 @@ Model.findById = function findById(id, projection, options, callback) {
|
|
|
2234
2235
|
* await Adventure.findOne({ country: 'Croatia' }, 'name length').exec();
|
|
2235
2236
|
*
|
|
2236
2237
|
* @param {Object} [conditions]
|
|
2237
|
-
* @param {Object|String|
|
|
2238
|
+
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2238
2239
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
|
|
2239
2240
|
* @param {Function} [callback]
|
|
2240
2241
|
* @return {Query}
|
|
@@ -2383,7 +2384,7 @@ Model.count = function count(conditions, callback) {
|
|
|
2383
2384
|
*
|
|
2384
2385
|
* Passing a `callback` executes the query.
|
|
2385
2386
|
*
|
|
2386
|
-
* #### Example
|
|
2387
|
+
* #### Example:
|
|
2387
2388
|
*
|
|
2388
2389
|
* Link.distinct('url', { clicks: {$gt: 100}}, function (err, result) {
|
|
2389
2390
|
* if (err) return handleError(err);
|
|
@@ -2532,7 +2533,7 @@ Model.$where = function $where() {
|
|
|
2532
2533
|
* @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
|
|
2533
2534
|
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://docs.mongodb.com/manual/reference/operator/update/) in `update`, Mongoose will wrap `update` in `$set` for you. This prevents you from accidentally overwriting the document. This option tells Mongoose to skip adding `$set`. An alternative to this would be using [Model.findOneAndReplace(conditions, update, options, callback)](https://mongoosejs.com/docs/api/model.html#model_Model.findOneAndReplace).
|
|
2534
2535
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
2535
|
-
* @param {Object|String|
|
|
2536
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2536
2537
|
* @param {Function} [callback]
|
|
2537
2538
|
* @return {Query}
|
|
2538
2539
|
* @see Tutorial /docs/tutorials/findoneandupdate.html
|
|
@@ -2748,7 +2749,7 @@ Model.findByIdAndUpdate = function(id, update, options, callback) {
|
|
|
2748
2749
|
* @param {Object} conditions
|
|
2749
2750
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
|
|
2750
2751
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2751
|
-
* @param {Object|String|
|
|
2752
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2752
2753
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2753
2754
|
* @param {Function} [callback]
|
|
2754
2755
|
* @return {Query}
|
|
@@ -2854,7 +2855,7 @@ Model.findByIdAndDelete = function(id, options, callback) {
|
|
|
2854
2855
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2855
2856
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2856
2857
|
* @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
|
|
2857
|
-
* @param {Object|String|
|
|
2858
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2858
2859
|
* @param {Function} [callback]
|
|
2859
2860
|
* @return {Query}
|
|
2860
2861
|
* @api public
|
|
@@ -2941,7 +2942,7 @@ Model.findOneAndReplace = function(filter, replacement, options, callback) {
|
|
|
2941
2942
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
|
|
2942
2943
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2943
2944
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2944
|
-
* @param {Object|String|
|
|
2945
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2945
2946
|
* @param {Function} [callback]
|
|
2946
2947
|
* @return {Query}
|
|
2947
2948
|
* @see mongodb https://www.mongodb.org/display/DOCS/findAndModify+Command
|
|
@@ -3007,7 +3008,7 @@ Model.findOneAndRemove = function(conditions, options, callback) {
|
|
|
3007
3008
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
|
|
3008
3009
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
3009
3010
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
3010
|
-
* @param {Object|String|
|
|
3011
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
3011
3012
|
* @param {Function} [callback]
|
|
3012
3013
|
* @return {Query}
|
|
3013
3014
|
* @see Model.findOneAndRemove #model_Model.findOneAndRemove
|
|
@@ -3287,11 +3288,11 @@ Model.startSession = function() {
|
|
|
3287
3288
|
*
|
|
3288
3289
|
* @param {Array|Object|*} doc(s)
|
|
3289
3290
|
* @param {Object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#insertMany)
|
|
3290
|
-
* @param {Boolean} [options.ordered
|
|
3291
|
-
* @param {Boolean} [options.rawResult
|
|
3292
|
-
* @param {Boolean} [options.lean
|
|
3293
|
-
* @param {Number} [options.limit
|
|
3294
|
-
* @param {String|Object|Array} [options.populate
|
|
3291
|
+
* @param {Boolean} [options.ordered=true] if true, will fail fast on the first error encountered. If false, will insert all the documents it can and report errors later. An `insertMany()` with `ordered = false` is called an "unordered" `insertMany()`.
|
|
3292
|
+
* @param {Boolean} [options.rawResult=false] if false, the returned promise resolves to the documents that passed mongoose document validation. If `true`, will return the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#~insertWriteOpCallback) with a `mongoose` property that contains `validationErrors` if this is an unordered `insertMany`.
|
|
3293
|
+
* @param {Boolean} [options.lean=false] if `true`, skips hydrating and validating the documents. This option is useful if you need the extra performance, but Mongoose won't validate the documents before inserting.
|
|
3294
|
+
* @param {Number} [options.limit=null] this limits the number of documents being processed (validation/casting) by mongoose in parallel, this does **NOT** send the documents in batches to MongoDB. Use this option if you're processing a large number of documents and your app is running out of memory.
|
|
3295
|
+
* @param {String|Object|Array} [options.populate=null] populates the result documents. This option is a no-op if `rawResult` is set.
|
|
3295
3296
|
* @param {Function} [callback] callback
|
|
3296
3297
|
* @return {Promise} resolving to the raw result from the MongoDB driver if `options.rawResult` was `true`, or the documents that passed validation, otherwise
|
|
3297
3298
|
* @api public
|
|
@@ -3613,7 +3614,7 @@ Model.bulkWrite = function(ops, options, callback) {
|
|
|
3613
3614
|
*
|
|
3614
3615
|
* `bulkSave` uses `bulkWrite` under the hood, so it's mostly useful when dealing with many documents (10K+)
|
|
3615
3616
|
*
|
|
3616
|
-
* @param {
|
|
3617
|
+
* @param {Array<Document>} documents
|
|
3617
3618
|
* @param {Object} [options] options passed to the underlying `bulkWrite()`
|
|
3618
3619
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](/docs/transactions.html).
|
|
3619
3620
|
* @param {String|number} [options.w=1] The [write concern](https://docs.mongodb.com/manual/reference/write-concern/). See [`Query#w()`](/docs/api.html#query_Query-w) for more information.
|
|
@@ -3687,10 +3688,10 @@ function handleSuccessfulWrite(document, resolve, reject) {
|
|
|
3687
3688
|
|
|
3688
3689
|
/**
|
|
3689
3690
|
*
|
|
3690
|
-
* @param {
|
|
3691
|
+
* @param {Array<Document>} documents The array of documents to build write operations of
|
|
3691
3692
|
* @param {Object} options
|
|
3692
3693
|
* @param {Boolean} options.skipValidation defaults to `false`, when set to true, building the write operations will bypass validating the documents.
|
|
3693
|
-
* @
|
|
3694
|
+
* @return {Array<Promise>} Returns a array of all Promises the function executes to be awaited.
|
|
3694
3695
|
*/
|
|
3695
3696
|
Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, options) {
|
|
3696
3697
|
if (!Array.isArray(documents)) {
|
|
@@ -3764,7 +3765,7 @@ Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, op
|
|
|
3764
3765
|
* const mongooseCandy = Candy.hydrate({ _id: '54108337212ffb6d459f854c', type: 'jelly bean' });
|
|
3765
3766
|
*
|
|
3766
3767
|
* @param {Object} obj
|
|
3767
|
-
* @param {Object|String|
|
|
3768
|
+
* @param {Object|String|String[]} [projection] optional projection containing which fields should be selected for this document
|
|
3768
3769
|
* @return {Document} document instance
|
|
3769
3770
|
* @api public
|
|
3770
3771
|
*/
|