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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
6.2.10 / 2022-04-04
|
|
2
|
+
===================
|
|
3
|
+
* fix(types): improve lastErrorObject typing for rawResults #11602 [simllll](https://github.com/simllll)
|
|
4
|
+
* docs(typescript): add note about deprecating extends Document #11619 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
|
5
|
+
* docs: consistent syntax highlighting with upgraded highlight.js #11579 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
|
6
|
+
|
|
1
7
|
6.2.9 / 2022-03-28
|
|
2
8
|
==================
|
|
3
9
|
* perf(document+model): make a few small optimizations #11380
|
package/dist/browser.umd.js
CHANGED
|
@@ -1590,7 +1590,7 @@ function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterat
|
|
|
1590
1590
|
* Creates an object that precomputes whether a given path has child fields in
|
|
1591
1591
|
* the projection.
|
|
1592
1592
|
*
|
|
1593
|
-
* ####Example:
|
|
1593
|
+
* #### Example:
|
|
1594
1594
|
* const res = hasIncludedChildren({ 'a.b.c': 0 });
|
|
1595
1595
|
* res.a; // 1
|
|
1596
1596
|
* res['a.b']; // 1
|
|
@@ -1624,7 +1624,7 @@ t.exports=function t(e,r,o){for(var s=(o=o||{}).typeOnly,a=-1===r.indexOf(".")?[
|
|
|
1624
1624
|
* If populating a path within a document array, make sure each
|
|
1625
1625
|
* subdoc within the array knows its subpaths are populated.
|
|
1626
1626
|
*
|
|
1627
|
-
* ####Example:
|
|
1627
|
+
* #### Example:
|
|
1628
1628
|
* const doc = await Article.findOne().populate('comments.author');
|
|
1629
1629
|
* doc.comments[0].populated('author'); // Should be set
|
|
1630
1630
|
*/t.exports=function(t,e){if(null!=t._id&&null!=e&&0!==e.length){var r,i=String(t._id),s=n(e);try{for(s.s();!(r=s.n()).done;){var a=r.value;if(!a.isVirtual)for(var u=a.path.split("."),h=0;h<u.length-1;++h){var f=u.slice(0,h+1).join("."),c=u.slice(h+1).join("."),l=t.get(f);if(null!=l&&o.isMongooseDocumentArray(l)){for(var d=0;d<l.length;++d)l[d].populated(c,null==a._docs[i]?void 0:a._docs[i][d],a);break}}}}catch(t){s.e(t)}finally{s.f()}}}},function(t,e,r){"use strict";
|
package/lib/aggregate.js
CHANGED
|
@@ -19,7 +19,7 @@ const readConcern = Query.prototype.readConcern;
|
|
|
19
19
|
* Aggregate constructor used for building aggregation pipelines. Do not
|
|
20
20
|
* instantiate this class directly, use [Model.aggregate()](/docs/api.html#model_Model.aggregate) instead.
|
|
21
21
|
*
|
|
22
|
-
* ####Example:
|
|
22
|
+
* #### Example:
|
|
23
23
|
*
|
|
24
24
|
* const aggregate = Model.aggregate([
|
|
25
25
|
* { $project: { a: 1, b: 1 } },
|
|
@@ -31,7 +31,7 @@ const readConcern = Query.prototype.readConcern;
|
|
|
31
31
|
* unwind('tags').
|
|
32
32
|
* exec(callback);
|
|
33
33
|
*
|
|
34
|
-
* ####Note:
|
|
34
|
+
* #### Note:
|
|
35
35
|
*
|
|
36
36
|
* - The documents returned are plain javascript objects, not mongoose documents (since any shape of document can be returned).
|
|
37
37
|
* - Mongoose does **not** cast pipeline stages. The below will **not** work unless `_id` is a string in the database
|
|
@@ -87,7 +87,7 @@ Aggregate.prototype.options;
|
|
|
87
87
|
/**
|
|
88
88
|
* Get/set the model that this aggregation will execute on.
|
|
89
89
|
*
|
|
90
|
-
* ####Example:
|
|
90
|
+
* #### Example:
|
|
91
91
|
* const aggregate = MyModel.aggregate([{ $match: { answer: 42 } }]);
|
|
92
92
|
* aggregate.model() === MyModel; // true
|
|
93
93
|
*
|
|
@@ -123,7 +123,7 @@ Aggregate.prototype.model = function(model) {
|
|
|
123
123
|
/**
|
|
124
124
|
* Appends new operators to this aggregate pipeline
|
|
125
125
|
*
|
|
126
|
-
* ####Examples:
|
|
126
|
+
* #### Examples:
|
|
127
127
|
*
|
|
128
128
|
* aggregate.append({ $project: { field: 1 }}, { $limit: 2 });
|
|
129
129
|
*
|
|
@@ -154,7 +154,7 @@ Aggregate.prototype.append = function() {
|
|
|
154
154
|
* Appends a new $addFields operator to this aggregate pipeline.
|
|
155
155
|
* Requires MongoDB v3.4+ to work
|
|
156
156
|
*
|
|
157
|
-
* ####Examples:
|
|
157
|
+
* #### Examples:
|
|
158
158
|
*
|
|
159
159
|
* // adding new fields based on existing fields
|
|
160
160
|
* aggregate.addFields({
|
|
@@ -185,7 +185,7 @@ Aggregate.prototype.addFields = function(arg) {
|
|
|
185
185
|
*
|
|
186
186
|
* Mongoose query [selection syntax](#query_Query-select) is also supported.
|
|
187
187
|
*
|
|
188
|
-
* ####Examples:
|
|
188
|
+
* #### Examples:
|
|
189
189
|
*
|
|
190
190
|
* // include a, include b, exclude _id
|
|
191
191
|
* aggregate.project("a b -_id");
|
|
@@ -240,7 +240,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
240
240
|
/**
|
|
241
241
|
* Appends a new custom $group operator to this aggregate pipeline.
|
|
242
242
|
*
|
|
243
|
-
* ####Examples:
|
|
243
|
+
* #### Examples:
|
|
244
244
|
*
|
|
245
245
|
* aggregate.group({ _id: "$department" });
|
|
246
246
|
*
|
|
@@ -256,7 +256,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
256
256
|
/**
|
|
257
257
|
* Appends a new custom $match operator to this aggregate pipeline.
|
|
258
258
|
*
|
|
259
|
-
* ####Examples:
|
|
259
|
+
* #### Examples:
|
|
260
260
|
*
|
|
261
261
|
* aggregate.match({ department: { $in: [ "sales", "engineering" ] } });
|
|
262
262
|
*
|
|
@@ -272,7 +272,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
272
272
|
/**
|
|
273
273
|
* Appends a new $skip operator to this aggregate pipeline.
|
|
274
274
|
*
|
|
275
|
-
* ####Examples:
|
|
275
|
+
* #### Examples:
|
|
276
276
|
*
|
|
277
277
|
* aggregate.skip(10);
|
|
278
278
|
*
|
|
@@ -288,7 +288,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
288
288
|
/**
|
|
289
289
|
* Appends a new $limit operator to this aggregate pipeline.
|
|
290
290
|
*
|
|
291
|
-
* ####Examples:
|
|
291
|
+
* #### Examples:
|
|
292
292
|
*
|
|
293
293
|
* aggregate.limit(10);
|
|
294
294
|
*
|
|
@@ -304,11 +304,11 @@ Aggregate.prototype.project = function(arg) {
|
|
|
304
304
|
/**
|
|
305
305
|
* Appends a new $geoNear operator to this aggregate pipeline.
|
|
306
306
|
*
|
|
307
|
-
* ####
|
|
307
|
+
* #### Note:
|
|
308
308
|
*
|
|
309
309
|
* **MUST** be used as the first operator in the pipeline.
|
|
310
310
|
*
|
|
311
|
-
* ####Examples:
|
|
311
|
+
* #### Examples:
|
|
312
312
|
*
|
|
313
313
|
* aggregate.near({
|
|
314
314
|
* near: [40.724, -73.997],
|
|
@@ -353,7 +353,7 @@ Aggregate.prototype.near = function(arg) {
|
|
|
353
353
|
* Note that the `$unwind` operator requires the path name to start with '$'.
|
|
354
354
|
* Mongoose will prepend '$' if the specified field doesn't start '$'.
|
|
355
355
|
*
|
|
356
|
-
* ####Examples:
|
|
356
|
+
* #### Examples:
|
|
357
357
|
*
|
|
358
358
|
* aggregate.unwind("tags");
|
|
359
359
|
* aggregate.unwind("a", "b", "c");
|
|
@@ -392,7 +392,7 @@ Aggregate.prototype.unwind = function() {
|
|
|
392
392
|
* If you are passing in a string Mongoose will prepend '$' if the specified field doesn't start '$'.
|
|
393
393
|
* If you are passing in an object the strings in your expression will not be altered.
|
|
394
394
|
*
|
|
395
|
-
* ####Examples:
|
|
395
|
+
* #### Examples:
|
|
396
396
|
*
|
|
397
397
|
* aggregate.replaceRoot("user");
|
|
398
398
|
*
|
|
@@ -423,7 +423,7 @@ Aggregate.prototype.replaceRoot = function(newRoot) {
|
|
|
423
423
|
/**
|
|
424
424
|
* Appends a new $count operator to this aggregate pipeline.
|
|
425
425
|
*
|
|
426
|
-
* ####Examples:
|
|
426
|
+
* #### Examples:
|
|
427
427
|
*
|
|
428
428
|
* aggregate.count("userCount");
|
|
429
429
|
*
|
|
@@ -444,7 +444,7 @@ Aggregate.prototype.count = function(countName) {
|
|
|
444
444
|
* Note that the `$sortByCount` operator requires the new root to start with '$'.
|
|
445
445
|
* Mongoose will prepend '$' if the specified field name doesn't start with '$'.
|
|
446
446
|
*
|
|
447
|
-
* ####Examples:
|
|
447
|
+
* #### Examples:
|
|
448
448
|
*
|
|
449
449
|
* aggregate.sortByCount('users');
|
|
450
450
|
* aggregate.sortByCount({ $mergeObjects: [ "$employee", "$business" ] })
|
|
@@ -471,7 +471,7 @@ Aggregate.prototype.sortByCount = function(arg) {
|
|
|
471
471
|
/**
|
|
472
472
|
* Appends new custom $lookup operator to this aggregate pipeline.
|
|
473
473
|
*
|
|
474
|
-
* ####Examples:
|
|
474
|
+
* #### Examples:
|
|
475
475
|
*
|
|
476
476
|
* aggregate.lookup({ from: 'users', localField: 'userId', foreignField: '_id', as: 'users' });
|
|
477
477
|
*
|
|
@@ -522,7 +522,7 @@ Aggregate.prototype.graphLookup = function(options) {
|
|
|
522
522
|
/**
|
|
523
523
|
* Appends new custom $sample operator to this aggregate pipeline.
|
|
524
524
|
*
|
|
525
|
-
* ####Examples:
|
|
525
|
+
* #### Examples:
|
|
526
526
|
*
|
|
527
527
|
* aggregate.sample(3); // Add a pipeline that picks 3 random documents
|
|
528
528
|
*
|
|
@@ -543,7 +543,7 @@ Aggregate.prototype.sample = function(size) {
|
|
|
543
543
|
*
|
|
544
544
|
* If a string is passed, it must be a space delimited list of path names. The sort order of each path is ascending unless the path name is prefixed with `-` which will be treated as descending.
|
|
545
545
|
*
|
|
546
|
-
* ####Examples:
|
|
546
|
+
* #### Examples:
|
|
547
547
|
*
|
|
548
548
|
* // these are equivalent
|
|
549
549
|
* aggregate.sort({ field: 'asc', test: -1 });
|
|
@@ -591,7 +591,7 @@ Aggregate.prototype.sort = function(arg) {
|
|
|
591
591
|
/**
|
|
592
592
|
* Appends new $unionWith operator to this aggregate pipeline.
|
|
593
593
|
*
|
|
594
|
-
* ####Examples:
|
|
594
|
+
* #### Examples:
|
|
595
595
|
*
|
|
596
596
|
* aggregate.unionWith({ coll: 'users', pipeline: [ { $match: { _id: 1 } } ] });
|
|
597
597
|
*
|
|
@@ -608,7 +608,7 @@ Aggregate.prototype.unionWith = function(options) {
|
|
|
608
608
|
/**
|
|
609
609
|
* Sets the readPreference option for the aggregation query.
|
|
610
610
|
*
|
|
611
|
-
* ####Example:
|
|
611
|
+
* #### Example:
|
|
612
612
|
*
|
|
613
613
|
* await Model.aggregate(pipeline).read('primaryPreferred');
|
|
614
614
|
*
|
|
@@ -631,7 +631,7 @@ Aggregate.prototype.read = function(pref, tags) {
|
|
|
631
631
|
/**
|
|
632
632
|
* Sets the readConcern level for the aggregation query.
|
|
633
633
|
*
|
|
634
|
-
* ####Example:
|
|
634
|
+
* #### Example:
|
|
635
635
|
*
|
|
636
636
|
* await Model.aggregate(pipeline).readConcern('majority');
|
|
637
637
|
*
|
|
@@ -655,7 +655,7 @@ Aggregate.prototype.readConcern = function(level) {
|
|
|
655
655
|
* If 3 arguments are supplied, Mongoose will wrap them with if-then-else of $cond operator respectively
|
|
656
656
|
* If `thenExpr` or `elseExpr` is string, make sure it starts with $$, like `$$DESCEND`, `$$PRUNE` or `$$KEEP`.
|
|
657
657
|
*
|
|
658
|
-
* ####Example:
|
|
658
|
+
* #### Example:
|
|
659
659
|
*
|
|
660
660
|
* await Model.aggregate(pipeline).redact({
|
|
661
661
|
* $cond: {
|
|
@@ -700,7 +700,7 @@ Aggregate.prototype.redact = function(expression, thenExpr, elseExpr) {
|
|
|
700
700
|
/**
|
|
701
701
|
* Execute the aggregation with explain
|
|
702
702
|
*
|
|
703
|
-
* ####Example:
|
|
703
|
+
* #### Example:
|
|
704
704
|
*
|
|
705
705
|
* Model.aggregate(..).explain(callback)
|
|
706
706
|
*
|
|
@@ -768,7 +768,7 @@ Aggregate.prototype.explain = function(verbosity, callback) {
|
|
|
768
768
|
/**
|
|
769
769
|
* Sets the allowDiskUse option for the aggregation query (ignored for < 2.6.0)
|
|
770
770
|
*
|
|
771
|
-
* ####Example:
|
|
771
|
+
* #### Example:
|
|
772
772
|
*
|
|
773
773
|
* await Model.aggregate([{ $match: { foo: 'bar' } }]).allowDiskUse(true);
|
|
774
774
|
*
|
|
@@ -785,7 +785,7 @@ Aggregate.prototype.allowDiskUse = function(value) {
|
|
|
785
785
|
/**
|
|
786
786
|
* Sets the hint option for the aggregation query (ignored for < 3.6.0)
|
|
787
787
|
*
|
|
788
|
-
* ####Example:
|
|
788
|
+
* #### Example:
|
|
789
789
|
*
|
|
790
790
|
* Model.aggregate(..).hint({ qty: 1, category: 1 }).exec(callback)
|
|
791
791
|
*
|
|
@@ -801,7 +801,7 @@ Aggregate.prototype.hint = function(value) {
|
|
|
801
801
|
/**
|
|
802
802
|
* Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html).
|
|
803
803
|
*
|
|
804
|
-
* ####Example:
|
|
804
|
+
* #### Example:
|
|
805
805
|
*
|
|
806
806
|
* const session = await Model.startSession();
|
|
807
807
|
* await Model.aggregate(..).session(session);
|
|
@@ -822,7 +822,7 @@ Aggregate.prototype.session = function(session) {
|
|
|
822
822
|
/**
|
|
823
823
|
* Lets you set arbitrary options, for middleware or plugins.
|
|
824
824
|
*
|
|
825
|
-
* ####Example:
|
|
825
|
+
* #### Example:
|
|
826
826
|
*
|
|
827
827
|
* const agg = Model.aggregate(..).option({ allowDiskUse: true }); // Set the `allowDiskUse` option
|
|
828
828
|
* agg.options; // `{ allowDiskUse: true }`
|
|
@@ -849,7 +849,7 @@ Aggregate.prototype.option = function(value) {
|
|
|
849
849
|
* Cursors are useful if you want to process the results of the aggregation one-at-a-time
|
|
850
850
|
* because the aggregation result is too big to fit into memory.
|
|
851
851
|
*
|
|
852
|
-
* ####Example:
|
|
852
|
+
* #### Example:
|
|
853
853
|
*
|
|
854
854
|
* const cursor = Model.aggregate(..).cursor({ batchSize: 1000 });
|
|
855
855
|
* cursor.eachAsync(function(doc, i) {
|
|
@@ -875,7 +875,7 @@ Aggregate.prototype.cursor = function(options) {
|
|
|
875
875
|
/**
|
|
876
876
|
* Adds a collation
|
|
877
877
|
*
|
|
878
|
-
* ####Example:
|
|
878
|
+
* #### Example:
|
|
879
879
|
*
|
|
880
880
|
* const res = await Model.aggregate(pipeline).collation({ locale: 'en_US', strength: 1 });
|
|
881
881
|
*
|
|
@@ -896,7 +896,7 @@ Aggregate.prototype.collation = function(collation) {
|
|
|
896
896
|
/**
|
|
897
897
|
* Combines multiple aggregation pipelines.
|
|
898
898
|
*
|
|
899
|
-
* ####Example:
|
|
899
|
+
* #### Example:
|
|
900
900
|
*
|
|
901
901
|
* const res = await Model.aggregate().facet({
|
|
902
902
|
* books: [{ groupBy: '$author' }],
|
|
@@ -919,7 +919,7 @@ Aggregate.prototype.facet = function(options) {
|
|
|
919
919
|
* Helper for [Atlas Text Search](https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/)'s
|
|
920
920
|
* `$search` stage.
|
|
921
921
|
*
|
|
922
|
-
* ####Example:
|
|
922
|
+
* #### Example:
|
|
923
923
|
*
|
|
924
924
|
* const res = await Model.aggregate().
|
|
925
925
|
* search({
|
|
@@ -944,7 +944,7 @@ Aggregate.prototype.search = function(options) {
|
|
|
944
944
|
/**
|
|
945
945
|
* Returns the current pipeline
|
|
946
946
|
*
|
|
947
|
-
* ####Example:
|
|
947
|
+
* #### Example:
|
|
948
948
|
*
|
|
949
949
|
* MyModel.aggregate().match({ test: 1 }).pipeline(); // [{ $match: { test: 1 } }]
|
|
950
950
|
*
|
|
@@ -960,7 +960,7 @@ Aggregate.prototype.pipeline = function() {
|
|
|
960
960
|
/**
|
|
961
961
|
* Executes the aggregate pipeline on the currently bound Model.
|
|
962
962
|
*
|
|
963
|
-
* ####Example:
|
|
963
|
+
* #### Example:
|
|
964
964
|
*
|
|
965
965
|
* aggregate.exec(callback);
|
|
966
966
|
*
|
|
@@ -1027,7 +1027,7 @@ Aggregate.prototype.exec = function(callback) {
|
|
|
1027
1027
|
/**
|
|
1028
1028
|
* Provides promise for aggregate.
|
|
1029
1029
|
*
|
|
1030
|
-
* ####Example:
|
|
1030
|
+
* #### Example:
|
|
1031
1031
|
*
|
|
1032
1032
|
* Model.aggregate(..).then(successCallback, errorCallback);
|
|
1033
1033
|
*
|
|
@@ -1059,7 +1059,7 @@ Aggregate.prototype.catch = function(reject) {
|
|
|
1059
1059
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
1060
1060
|
* will call it for you.
|
|
1061
1061
|
*
|
|
1062
|
-
* ####Example
|
|
1062
|
+
* #### Example
|
|
1063
1063
|
*
|
|
1064
1064
|
* const agg = Model.aggregate([{ $match: { age: { $gte: 25 } } }]);
|
|
1065
1065
|
* for await (const doc of agg) {
|
package/lib/browser.js
CHANGED
|
@@ -46,7 +46,7 @@ exports.Error = require('./error/index');
|
|
|
46
46
|
/**
|
|
47
47
|
* The Mongoose [Schema](#schema_Schema) constructor
|
|
48
48
|
*
|
|
49
|
-
* ####Example:
|
|
49
|
+
* #### Example:
|
|
50
50
|
*
|
|
51
51
|
* const mongoose = require('mongoose');
|
|
52
52
|
* const Schema = mongoose.Schema;
|
|
@@ -61,12 +61,12 @@ exports.Schema = require('./schema');
|
|
|
61
61
|
/**
|
|
62
62
|
* The various Mongoose Types.
|
|
63
63
|
*
|
|
64
|
-
* ####Example:
|
|
64
|
+
* #### Example:
|
|
65
65
|
*
|
|
66
66
|
* const mongoose = require('mongoose');
|
|
67
67
|
* const array = mongoose.Types.Array;
|
|
68
68
|
*
|
|
69
|
-
* ####Types:
|
|
69
|
+
* #### Types:
|
|
70
70
|
*
|
|
71
71
|
* - [Array](/docs/schematypes.html#arrays)
|
|
72
72
|
* - [Buffer](/docs/schematypes.html#buffers)
|
|
@@ -98,7 +98,7 @@ exports.VirtualType = require('./virtualtype');
|
|
|
98
98
|
/**
|
|
99
99
|
* The various Mongoose SchemaTypes.
|
|
100
100
|
*
|
|
101
|
-
* ####Note:
|
|
101
|
+
* #### Note:
|
|
102
102
|
*
|
|
103
103
|
* _Alias of mongoose.Schema.Types for backwards compatibility._
|
|
104
104
|
*
|
package/lib/connection.js
CHANGED
|
@@ -92,7 +92,7 @@ Connection.prototype.__proto__ = EventEmitter.prototype;
|
|
|
92
92
|
*
|
|
93
93
|
* Each state change emits its associated event name.
|
|
94
94
|
*
|
|
95
|
-
* ####Example
|
|
95
|
+
* #### Example
|
|
96
96
|
*
|
|
97
97
|
* conn.on('connected', callback);
|
|
98
98
|
* conn.on('disconnected', callback);
|
|
@@ -131,7 +131,7 @@ Object.defineProperty(Connection.prototype, 'readyState', {
|
|
|
131
131
|
/**
|
|
132
132
|
* Gets the value of the option `key`. Equivalent to `conn.options[key]`
|
|
133
133
|
*
|
|
134
|
-
* ####Example:
|
|
134
|
+
* #### Example:
|
|
135
135
|
*
|
|
136
136
|
* conn.get('test'); // returns the 'test' value
|
|
137
137
|
*
|
|
@@ -155,7 +155,7 @@ Connection.prototype.get = function(key) {
|
|
|
155
155
|
*
|
|
156
156
|
* - `maxTimeMS`: Set [`maxTimeMS`](/docs/api.html#query_Query-maxTimeMS) for all queries on this connection.
|
|
157
157
|
*
|
|
158
|
-
* ####Example:
|
|
158
|
+
* #### Example:
|
|
159
159
|
*
|
|
160
160
|
* conn.set('test', 'foo');
|
|
161
161
|
* conn.get('test'); // 'foo'
|
|
@@ -192,7 +192,7 @@ Connection.prototype.collections;
|
|
|
192
192
|
/**
|
|
193
193
|
* The name of the database this connection points to.
|
|
194
194
|
*
|
|
195
|
-
* ####Example
|
|
195
|
+
* #### Example
|
|
196
196
|
*
|
|
197
197
|
* mongoose.createConnection('mongodb://localhost:27017/mydb').name; // "mydb"
|
|
198
198
|
*
|
|
@@ -209,7 +209,7 @@ Connection.prototype.name;
|
|
|
209
209
|
* a map from model names to models. Contains all models that have been
|
|
210
210
|
* added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
|
|
211
211
|
*
|
|
212
|
-
* ####Example
|
|
212
|
+
* #### Example
|
|
213
213
|
*
|
|
214
214
|
* const conn = mongoose.createConnection();
|
|
215
215
|
* const Test = conn.model('Test', mongoose.Schema({ name: String }));
|
|
@@ -229,7 +229,7 @@ Connection.prototype.models;
|
|
|
229
229
|
* A number identifier for this connection. Used for debugging when
|
|
230
230
|
* you have [multiple connections](/docs/connections.html#multiple_connections).
|
|
231
231
|
*
|
|
232
|
-
* ####Example
|
|
232
|
+
* #### Example
|
|
233
233
|
*
|
|
234
234
|
* // The default connection has `id = 0`
|
|
235
235
|
* mongoose.connection.id; // 0
|
|
@@ -249,7 +249,7 @@ Connection.prototype.id;
|
|
|
249
249
|
/**
|
|
250
250
|
* The plugins that will be applied to all models created on this connection.
|
|
251
251
|
*
|
|
252
|
-
* ####Example:
|
|
252
|
+
* #### Example:
|
|
253
253
|
*
|
|
254
254
|
* const db = mongoose.createConnection('mongodb://localhost:27017/mydb');
|
|
255
255
|
* db.plugin(() => console.log('Applied'));
|
|
@@ -273,7 +273,7 @@ Object.defineProperty(Connection.prototype, 'plugins', {
|
|
|
273
273
|
* The host name portion of the URI. If multiple hosts, such as a replica set,
|
|
274
274
|
* this will contain the first host name in the URI
|
|
275
275
|
*
|
|
276
|
-
* ####Example
|
|
276
|
+
* #### Example
|
|
277
277
|
*
|
|
278
278
|
* mongoose.createConnection('mongodb://localhost:27017/mydb').host; // "localhost"
|
|
279
279
|
*
|
|
@@ -293,7 +293,7 @@ Object.defineProperty(Connection.prototype, 'host', {
|
|
|
293
293
|
* The port portion of the URI. If multiple hosts, such as a replica set,
|
|
294
294
|
* this will contain the port from the first host name in the URI.
|
|
295
295
|
*
|
|
296
|
-
* ####Example
|
|
296
|
+
* #### Example
|
|
297
297
|
*
|
|
298
298
|
* mongoose.createConnection('mongodb://localhost:27017/mydb').port; // 27017
|
|
299
299
|
*
|
|
@@ -312,7 +312,7 @@ Object.defineProperty(Connection.prototype, 'port', {
|
|
|
312
312
|
/**
|
|
313
313
|
* The username specified in the URI
|
|
314
314
|
*
|
|
315
|
-
* ####Example
|
|
315
|
+
* #### Example
|
|
316
316
|
*
|
|
317
317
|
* mongoose.createConnection('mongodb://val:psw@localhost:27017/mydb').user; // "val"
|
|
318
318
|
*
|
|
@@ -331,7 +331,7 @@ Object.defineProperty(Connection.prototype, 'user', {
|
|
|
331
331
|
/**
|
|
332
332
|
* The password specified in the URI
|
|
333
333
|
*
|
|
334
|
-
* ####Example
|
|
334
|
+
* #### Example
|
|
335
335
|
*
|
|
336
336
|
* mongoose.createConnection('mongodb://val:psw@localhost:27017/mydb').pass; // "psw"
|
|
337
337
|
*
|
|
@@ -409,7 +409,7 @@ Connection.prototype.createCollection = _wrapConnHelper(function createCollectio
|
|
|
409
409
|
* for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
|
|
410
410
|
* and [transactions](https://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
411
411
|
*
|
|
412
|
-
* ####Example:
|
|
412
|
+
* #### Example:
|
|
413
413
|
*
|
|
414
414
|
* const session = await conn.startSession();
|
|
415
415
|
* let doc = await Person.findOne({ name: 'Ned Stark' }, null, { session });
|
|
@@ -447,7 +447,7 @@ Connection.prototype.startSession = _wrapConnHelper(function startSession(option
|
|
|
447
447
|
* Calls the MongoDB driver's [`session.withTransaction()`](https://mongodb.github.io/node-mongodb-native/3.5/api/ClientSession.html#withTransaction),
|
|
448
448
|
* but also handles resetting Mongoose document state as shown below.
|
|
449
449
|
*
|
|
450
|
-
* ####Example:
|
|
450
|
+
* #### Example:
|
|
451
451
|
*
|
|
452
452
|
* const doc = new Person({ name: 'Will Riker' });
|
|
453
453
|
* await db.transaction(async function setRank(session) {
|
|
@@ -532,7 +532,7 @@ Connection.prototype.dropCollection = _wrapConnHelper(function dropCollection(co
|
|
|
532
532
|
* Helper for `dropDatabase()`. Deletes the given database, including all
|
|
533
533
|
* collections, documents, and indexes.
|
|
534
534
|
*
|
|
535
|
-
* ####Example:
|
|
535
|
+
* #### Example:
|
|
536
536
|
*
|
|
537
537
|
* const conn = mongoose.createConnection('mongodb://localhost:27017/mydb');
|
|
538
538
|
* // Deletes the entire 'mydb' database
|
|
@@ -1037,7 +1037,7 @@ Connection.prototype.collection = function(name, options) {
|
|
|
1037
1037
|
*
|
|
1038
1038
|
* Equivalent to calling `.plugin(fn)` on each schema you create.
|
|
1039
1039
|
*
|
|
1040
|
-
* ####Example:
|
|
1040
|
+
* #### Example:
|
|
1041
1041
|
* const db = mongoose.createConnection('mongodb://localhost:27017/mydb');
|
|
1042
1042
|
* db.plugin(() => console.log('Applied'));
|
|
1043
1043
|
* db.plugins.length; // 1
|
|
@@ -1067,7 +1067,7 @@ Connection.prototype.plugin = function(fn, opts) {
|
|
|
1067
1067
|
*
|
|
1068
1068
|
* _When no `collection` argument is passed, Mongoose produces a collection name by passing the model `name` to the [utils.toCollectionName](#utils_exports.toCollectionName) method. This method pluralizes the name. If you don't like this behavior, either pass a collection name or set your schemas collection name option._
|
|
1069
1069
|
*
|
|
1070
|
-
* ####Example:
|
|
1070
|
+
* #### Example:
|
|
1071
1071
|
*
|
|
1072
1072
|
* const schema = new Schema({ name: String }, { collection: 'actor' });
|
|
1073
1073
|
*
|
|
@@ -1185,7 +1185,7 @@ Connection.prototype.model = function(name, schema, collection, options) {
|
|
|
1185
1185
|
* use this function to clean up any models you created in your tests to
|
|
1186
1186
|
* prevent OverwriteModelErrors.
|
|
1187
1187
|
*
|
|
1188
|
-
* ####Example:
|
|
1188
|
+
* #### Example:
|
|
1189
1189
|
*
|
|
1190
1190
|
* conn.model('User', new Schema({ name: String }));
|
|
1191
1191
|
* console.log(conn.model('User')); // Model object
|
|
@@ -1243,7 +1243,7 @@ Connection.prototype.deleteModel = function(name) {
|
|
|
1243
1243
|
* - 'end': Emitted if the underlying stream is closed
|
|
1244
1244
|
* - 'close': Emitted if the underlying stream is closed
|
|
1245
1245
|
*
|
|
1246
|
-
* ####Example:
|
|
1246
|
+
* #### Example:
|
|
1247
1247
|
*
|
|
1248
1248
|
* const User = conn.model('User', new Schema({ name: String }));
|
|
1249
1249
|
*
|
|
@@ -1287,7 +1287,7 @@ Connection.prototype.watch = function(pipeline, options) {
|
|
|
1287
1287
|
* successfully connects to MongoDB, or rejects if this connection failed
|
|
1288
1288
|
* to connect.
|
|
1289
1289
|
*
|
|
1290
|
-
* ####Example:
|
|
1290
|
+
* #### Example:
|
|
1291
1291
|
* const conn = await mongoose.createConnection('mongodb://localhost:27017/test').
|
|
1292
1292
|
* asPromise();
|
|
1293
1293
|
* conn.readyState; // 1, means Mongoose is connected
|
|
@@ -1356,7 +1356,7 @@ Connection.prototype.optionsProvideAuthenticationData = function(options) {
|
|
|
1356
1356
|
* Returns the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
1357
1357
|
* that this connection uses to talk to MongoDB.
|
|
1358
1358
|
*
|
|
1359
|
-
* ####Example:
|
|
1359
|
+
* #### Example:
|
|
1360
1360
|
* const conn = await mongoose.createConnection('mongodb://localhost:27017/test');
|
|
1361
1361
|
*
|
|
1362
1362
|
* conn.getClient(); // MongoClient { ... }
|
|
@@ -1374,7 +1374,7 @@ Connection.prototype.getClient = function getClient() {
|
|
|
1374
1374
|
* that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
|
|
1375
1375
|
* reuse it.
|
|
1376
1376
|
*
|
|
1377
|
-
* ####Example:
|
|
1377
|
+
* #### Example:
|
|
1378
1378
|
* const client = await mongodb.MongoClient.connect('mongodb://localhost:27017/test');
|
|
1379
1379
|
*
|
|
1380
1380
|
* const conn = mongoose.createConnection().setClient(client);
|
|
@@ -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.
|
|
@@ -226,7 +226,7 @@ AggregationCursor.prototype.eachAsync = function(fn, opts, callback) {
|
|
|
226
226
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
227
227
|
* will call it for you.
|
|
228
228
|
*
|
|
229
|
-
* ####Example
|
|
229
|
+
* #### Example
|
|
230
230
|
*
|
|
231
231
|
* // Async iterator without explicitly calling `cursor()`. Mongoose still
|
|
232
232
|
* // 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.
|
|
@@ -211,7 +211,7 @@ QueryCursor.prototype.next = function(callback) {
|
|
|
211
211
|
* will wait for the promise to resolve before iterating on to the next one.
|
|
212
212
|
* Returns a promise that resolves when done.
|
|
213
213
|
*
|
|
214
|
-
* ####Example
|
|
214
|
+
* #### Example
|
|
215
215
|
*
|
|
216
216
|
* // Iterate over documents asynchronously
|
|
217
217
|
* Thing.
|
|
@@ -298,7 +298,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
|
|
|
298
298
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
299
299
|
* will call it for you.
|
|
300
300
|
*
|
|
301
|
-
* ####Example
|
|
301
|
+
* #### Example
|
|
302
302
|
*
|
|
303
303
|
* // Works without using `cursor()`
|
|
304
304
|
* for await (const doc of Model.find([{ $sort: { name: 1 } }])) {
|