mongoose 6.4.6 → 6.4.7
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 +32 -30
- package/lib/browser.js +1 -1
- package/lib/cast.js +2 -2
- package/lib/collection.js +1 -1
- package/lib/connection.js +34 -16
- package/lib/document.js +174 -101
- package/lib/index.js +2 -2
- package/lib/model.js +10 -10
- package/lib/query.js +10 -10
- package/lib/schema.js +1 -1
- package/lib/schematype.js +95 -81
- package/lib/virtualtype.js +14 -16
- package/package.json +2 -2
- package/types/connection.d.ts +1 -1
- package/types/models.d.ts +5 -5
package/lib/virtualtype.js
CHANGED
|
@@ -13,18 +13,18 @@ const utils = require('./utils');
|
|
|
13
13
|
* fullname instanceof mongoose.VirtualType // true
|
|
14
14
|
*
|
|
15
15
|
* @param {Object} options
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
16
|
+
* @param {String|Function} [options.ref] if `ref` is not nullish, this becomes a [populated virtual](/docs/populate.html#populate-virtuals)
|
|
17
|
+
* @param {String|Function} [options.localField] the local field to populate on if this is a populated virtual.
|
|
18
|
+
* @param {String|Function} [options.foreignField] the foreign field to populate on if this is a populated virtual.
|
|
19
|
+
* @param {Boolean} [options.justOne=false] by default, a populated virtual is an array. If you set `justOne`, the populated virtual will be a single doc or `null`.
|
|
20
|
+
* @param {Boolean} [options.getters=false] if you set this to `true`, Mongoose will call any custom getters you defined on this virtual
|
|
21
|
+
* @param {Boolean} [options.count=false] if you set this to `true`, `populate()` will set this virtual to the number of populated documents, as opposed to the documents themselves, using [`Query#countDocuments()`](./api.html#query_Query-countDocuments)
|
|
22
22
|
* @param {Object|Function} [options.match=null] add an extra match condition to `populate()`
|
|
23
23
|
* @param {Number} [options.limit=null] add a default `limit` to the `populate()` query
|
|
24
24
|
* @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
|
|
25
25
|
* @param {Number} [options.perDocumentLimit=null] For legacy reasons, `limit` with `populate()` may give incorrect results because it only executes a single query for every document being populated. If you set `perDocumentLimit`, Mongoose will ensure correct `limit` per document by executing a separate query for each document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })` will execute 2 additional queries if `.find()` returns 2 documents.
|
|
26
26
|
* @param {Object} [options.options=null] Additional options like `limit` and `lean`.
|
|
27
|
-
* @param {
|
|
27
|
+
* @param {String} name
|
|
28
28
|
* @api public
|
|
29
29
|
*/
|
|
30
30
|
|
|
@@ -36,10 +36,8 @@ function VirtualType(options, name) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* If no getters/
|
|
39
|
+
* If no getters/setters, add a default
|
|
40
40
|
*
|
|
41
|
-
* @param {Function} fn
|
|
42
|
-
* @return {VirtualType} this
|
|
43
41
|
* @api private
|
|
44
42
|
*/
|
|
45
43
|
|
|
@@ -51,10 +49,10 @@ VirtualType.prototype._applyDefaultGetters = function() {
|
|
|
51
49
|
const path = this.path;
|
|
52
50
|
const internalProperty = '$' + path;
|
|
53
51
|
this.getters.push(function() {
|
|
54
|
-
return this[internalProperty];
|
|
52
|
+
return this.$locals[internalProperty];
|
|
55
53
|
});
|
|
56
54
|
this.setters.push(function(v) {
|
|
57
|
-
this[internalProperty] = v;
|
|
55
|
+
this.$locals[internalProperty] = v;
|
|
58
56
|
});
|
|
59
57
|
};
|
|
60
58
|
|
|
@@ -85,7 +83,7 @@ VirtualType.prototype.clone = function() {
|
|
|
85
83
|
* return this.name.first + ' ' + this.name.last;
|
|
86
84
|
* });
|
|
87
85
|
*
|
|
88
|
-
* @param {
|
|
86
|
+
* @param {Function} fn
|
|
89
87
|
* @return {VirtualType} this
|
|
90
88
|
* @api public
|
|
91
89
|
*/
|
|
@@ -120,7 +118,7 @@ VirtualType.prototype.get = function(fn) {
|
|
|
120
118
|
* doc.name.first; // 'Jean-Luc'
|
|
121
119
|
* doc.name.last; // 'Picard'
|
|
122
120
|
*
|
|
123
|
-
* @param {
|
|
121
|
+
* @param {Function} fn
|
|
124
122
|
* @return {VirtualType} this
|
|
125
123
|
* @api public
|
|
126
124
|
*/
|
|
@@ -135,7 +133,7 @@ VirtualType.prototype.set = function(fn) {
|
|
|
135
133
|
*
|
|
136
134
|
* @param {Object} value
|
|
137
135
|
* @param {Document} doc The document this virtual is attached to
|
|
138
|
-
* @return {
|
|
136
|
+
* @return {Any} the value after applying all getters
|
|
139
137
|
* @api public
|
|
140
138
|
*/
|
|
141
139
|
|
|
@@ -158,7 +156,7 @@ VirtualType.prototype.applyGetters = function(value, doc) {
|
|
|
158
156
|
*
|
|
159
157
|
* @param {Object} value
|
|
160
158
|
* @param {Document} doc
|
|
161
|
-
* @return {
|
|
159
|
+
* @return {Any} the value after applying all setters
|
|
162
160
|
* @api public
|
|
163
161
|
*/
|
|
164
162
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.4.
|
|
4
|
+
"version": "6.4.7",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"serve-handler": "6.1.3",
|
|
61
61
|
"sinon": "14.0.0",
|
|
62
62
|
"stream-browserify": "3.0.0",
|
|
63
|
-
"ts-benchmark": "^1.1.
|
|
63
|
+
"ts-benchmark": "^1.1.10",
|
|
64
64
|
"tsd": "0.20.0",
|
|
65
65
|
"typescript": "4.7.4",
|
|
66
66
|
"uuid": "8.3.2",
|
package/types/connection.d.ts
CHANGED
|
@@ -229,7 +229,7 @@ declare module 'mongoose' {
|
|
|
229
229
|
/** The username specified in the URI */
|
|
230
230
|
readonly user: string;
|
|
231
231
|
|
|
232
|
-
/** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model
|
|
232
|
+
/** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model-watch). */
|
|
233
233
|
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
|
|
234
234
|
}
|
|
235
235
|
|
package/types/models.d.ts
CHANGED
|
@@ -306,11 +306,11 @@ declare module 'mongoose' {
|
|
|
306
306
|
estimatedDocumentCount(options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
307
307
|
|
|
308
308
|
/**
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
exists(filter: FilterQuery<T>, callback: Callback<
|
|
313
|
-
exists(filter: FilterQuery<T>): QueryWithHelpers<
|
|
309
|
+
* Returns a document with its `_id` if at least one document exists in the database that matches
|
|
310
|
+
* the given `filter`, and `null` otherwise.
|
|
311
|
+
*/
|
|
312
|
+
exists(filter: FilterQuery<T>, callback: Callback<{ _id: InferId<T> } | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
313
|
+
exists(filter: FilterQuery<T>): QueryWithHelpers<{ _id: InferId<T> } | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
314
314
|
|
|
315
315
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
316
316
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|