mongoose 7.6.4 → 7.6.6
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/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +1 -1
- package/lib/cursor/ChangeStream.js +3 -0
- package/lib/document.js +5 -2
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +6 -2
- package/lib/helpers/populate/assignVals.js +4 -2
- package/lib/model.js +6 -1
- package/lib/schema/SubdocumentPath.js +0 -1
- package/lib/schema/documentarray.js +2 -2
- package/lib/schema.js +1 -1
- package/lib/statemachine.js +5 -1
- package/lib/types/array/methods/index.js +12 -9
- package/package.json +6 -4
- package/types/index.d.ts +2 -1
- package/types/middlewares.d.ts +3 -1
- package/types/models.d.ts +11 -6
- package/types/query.d.ts +46 -46
package/lib/aggregate.js
CHANGED
|
@@ -665,7 +665,7 @@ Aggregate.prototype.unionWith = function(options) {
|
|
|
665
665
|
* await Model.aggregate(pipeline).read('primaryPreferred');
|
|
666
666
|
*
|
|
667
667
|
* @param {String|ReadPreference} pref one of the listed preference options or their aliases
|
|
668
|
-
* @param {Array} [tags] optional tags for this query.
|
|
668
|
+
* @param {Array} [tags] optional tags for this query.
|
|
669
669
|
* @return {Aggregate} this
|
|
670
670
|
* @api public
|
|
671
671
|
* @see mongodb https://www.mongodb.com/docs/manual/applications/replication/#read-preference
|
|
@@ -89,6 +89,9 @@ class ChangeStream extends EventEmitter {
|
|
|
89
89
|
if (ev === 'error' && this.closed) {
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
+
if (data != null && data.fullDocument != null && this.options && this.options.hydrate) {
|
|
93
|
+
data.fullDocument = this.options.model.hydrate(data.fullDocument);
|
|
94
|
+
}
|
|
92
95
|
this.emit(ev, data);
|
|
93
96
|
});
|
|
94
97
|
});
|
package/lib/document.js
CHANGED
|
@@ -1181,6 +1181,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1181
1181
|
this.invalidate(path, new MongooseError.CastError('Object', val, path));
|
|
1182
1182
|
return this;
|
|
1183
1183
|
}
|
|
1184
|
+
const wasModified = this.$isModified(path);
|
|
1184
1185
|
const hasInitialVal = this.$__.savedState != null && this.$__.savedState.hasOwnProperty(path);
|
|
1185
1186
|
if (this.$__.savedState != null && !this.$isNew && !this.$__.savedState.hasOwnProperty(path)) {
|
|
1186
1187
|
const initialVal = this.$__getValue(path);
|
|
@@ -1203,9 +1204,11 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1203
1204
|
|
|
1204
1205
|
this.$__setValue(path, {});
|
|
1205
1206
|
for (const key of keys) {
|
|
1206
|
-
this.$set(path + '.' + key, val[key], constructing, options);
|
|
1207
|
+
this.$set(path + '.' + key, val[key], constructing, { ...options, _skipMarkModified: true });
|
|
1207
1208
|
}
|
|
1208
|
-
if (priorVal != null &&
|
|
1209
|
+
if (priorVal != null &&
|
|
1210
|
+
(!wasModified || hasInitialVal) &&
|
|
1211
|
+
utils.deepEqual(hasInitialVal ? this.$__.savedState[path] : priorVal, val)) {
|
|
1209
1212
|
this.unmarkModified(path);
|
|
1210
1213
|
} else {
|
|
1211
1214
|
this.markModified(path);
|
|
@@ -32,9 +32,13 @@ const kHasArray = Symbol('assignRawDocsToIdStructure.hasArray');
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
function assignRawDocsToIdStructure(rawIds, resultDocs, resultOrder, options, recursed) {
|
|
35
|
-
// honor user specified sort order
|
|
35
|
+
// honor user specified sort order, unless we're populating a single
|
|
36
|
+
// virtual underneath an array (e.g. populating `employees.mostRecentShift` where
|
|
37
|
+
// `mostRecentShift` is a virtual with `justOne`)
|
|
36
38
|
const newOrder = [];
|
|
37
|
-
const sorting = options.
|
|
39
|
+
const sorting = options.isVirtual && options.justOne && rawIds.length > 1
|
|
40
|
+
? false :
|
|
41
|
+
options.sort && rawIds.length > 1;
|
|
38
42
|
const nullIfNotFound = options.$nullIfNotFound;
|
|
39
43
|
let doc;
|
|
40
44
|
let sid;
|
|
@@ -19,7 +19,8 @@ module.exports = function assignVals(o) {
|
|
|
19
19
|
// `o.options` contains options explicitly listed in `populateOptions`, like
|
|
20
20
|
// `match` and `limit`.
|
|
21
21
|
const populateOptions = Object.assign({}, o.options, userOptions, {
|
|
22
|
-
justOne: o.justOne
|
|
22
|
+
justOne: o.justOne,
|
|
23
|
+
isVirtual: o.isVirtual
|
|
23
24
|
});
|
|
24
25
|
populateOptions.$nullIfNotFound = o.isVirtual;
|
|
25
26
|
const populatedModel = o.populatedModel;
|
|
@@ -144,7 +145,7 @@ module.exports = function assignVals(o) {
|
|
|
144
145
|
|
|
145
146
|
const parts = _path.split('.');
|
|
146
147
|
let cur = docs[i];
|
|
147
|
-
|
|
148
|
+
let curPath = parts[0];
|
|
148
149
|
for (let j = 0; j < parts.length - 1; ++j) {
|
|
149
150
|
// If we get to an array with a dotted path, like `arr.foo`, don't set
|
|
150
151
|
// `foo` on the array.
|
|
@@ -167,6 +168,7 @@ module.exports = function assignVals(o) {
|
|
|
167
168
|
cur[parts[j]] = {};
|
|
168
169
|
}
|
|
169
170
|
cur = cur[parts[j]];
|
|
171
|
+
curPath += parts[j + 1] ? `.${parts[j + 1]}` : '';
|
|
170
172
|
// If the property in MongoDB is a primitive, we won't be able to populate
|
|
171
173
|
// the nested path, so skip it. See gh-7545
|
|
172
174
|
if (typeof cur !== 'object') {
|
package/lib/model.js
CHANGED
|
@@ -1516,7 +1516,12 @@ Model.diffIndexes = async function diffIndexes() {
|
|
|
1516
1516
|
|
|
1517
1517
|
const model = this;
|
|
1518
1518
|
|
|
1519
|
-
let dbIndexes = await model.listIndexes()
|
|
1519
|
+
let dbIndexes = await model.listIndexes().catch(err => {
|
|
1520
|
+
if (err.codeName == 'NamespaceNotFound') {
|
|
1521
|
+
return undefined;
|
|
1522
|
+
}
|
|
1523
|
+
throw err;
|
|
1524
|
+
});
|
|
1520
1525
|
if (dbIndexes === undefined) {
|
|
1521
1526
|
dbIndexes = [];
|
|
1522
1527
|
}
|
|
@@ -55,7 +55,6 @@ function SubdocumentPath(schema, path, options) {
|
|
|
55
55
|
this.$isSingleNested = true;
|
|
56
56
|
this.base = schema.base;
|
|
57
57
|
SchemaType.call(this, path, options, 'Embedded');
|
|
58
|
-
|
|
59
58
|
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) {
|
|
60
59
|
for (const disc of schema._applyDiscriminators.keys()) {
|
|
61
60
|
this.discriminator(disc, schema._applyDiscriminators.get(disc));
|
|
@@ -89,7 +89,7 @@ function DocumentArrayPath(key, schema, options, schemaOptions) {
|
|
|
89
89
|
this.$embeddedSchemaType.caster = this.Constructor;
|
|
90
90
|
this.$embeddedSchemaType.schema = this.schema;
|
|
91
91
|
|
|
92
|
-
if (schema._applyDiscriminators != null) {
|
|
92
|
+
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) {
|
|
93
93
|
for (const disc of schema._applyDiscriminators.keys()) {
|
|
94
94
|
this.discriminator(disc, schema._applyDiscriminators.get(disc));
|
|
95
95
|
}
|
|
@@ -528,7 +528,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
528
528
|
|
|
529
529
|
DocumentArrayPath.prototype.clone = function() {
|
|
530
530
|
const options = Object.assign({}, this.options);
|
|
531
|
-
const schematype = new this.constructor(this.path, this.schema, options, this.schemaOptions);
|
|
531
|
+
const schematype = new this.constructor(this.path, this.schema, { ...options, _skipApplyDiscriminators: true }, this.schemaOptions);
|
|
532
532
|
schematype.validators = this.validators.slice();
|
|
533
533
|
if (this.requiredValidator !== undefined) {
|
|
534
534
|
schematype.requiredValidator = this.requiredValidator;
|
package/lib/schema.js
CHANGED
|
@@ -2577,7 +2577,7 @@ Schema.prototype._getSchema = function(path) {
|
|
|
2577
2577
|
if (parts[p] === '$' || isArrayFilter(parts[p])) {
|
|
2578
2578
|
if (p + 1 === parts.length) {
|
|
2579
2579
|
// comments.$
|
|
2580
|
-
return foundschema;
|
|
2580
|
+
return foundschema.$embeddedSchemaType;
|
|
2581
2581
|
}
|
|
2582
2582
|
// comments.$.comments.$.title
|
|
2583
2583
|
ret = search(parts.slice(p + 1), foundschema.schema);
|
package/lib/statemachine.js
CHANGED
|
@@ -65,7 +65,11 @@ StateMachine.ctor = function() {
|
|
|
65
65
|
*/
|
|
66
66
|
|
|
67
67
|
StateMachine.prototype._changeState = function _changeState(path, nextState) {
|
|
68
|
-
const
|
|
68
|
+
const prevState = this.paths[path];
|
|
69
|
+
if (prevState === nextState) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const prevBucket = this.states[prevState];
|
|
69
73
|
if (prevBucket) delete prevBucket[path];
|
|
70
74
|
|
|
71
75
|
this.paths[path] = nextState;
|
|
@@ -374,7 +374,15 @@ const methods = {
|
|
|
374
374
|
if (val != null && utils.hasUserDefinedProperty(val, '$each')) {
|
|
375
375
|
atomics.$push = val;
|
|
376
376
|
} else {
|
|
377
|
-
|
|
377
|
+
if (val.length === 1) {
|
|
378
|
+
atomics.$push.$each.push(val[0]);
|
|
379
|
+
} else if (val.length < 10000) {
|
|
380
|
+
atomics.$push.$each.push(...val);
|
|
381
|
+
} else {
|
|
382
|
+
for (const v of val) {
|
|
383
|
+
atomics.$push.$each.push(v);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
378
386
|
}
|
|
379
387
|
} else {
|
|
380
388
|
atomics[op] = val;
|
|
@@ -403,8 +411,7 @@ const methods = {
|
|
|
403
411
|
addToSet() {
|
|
404
412
|
_checkManualPopulation(this, arguments);
|
|
405
413
|
|
|
406
|
-
|
|
407
|
-
values = this[arraySchemaSymbol].applySetters(values, this[arrayParentSymbol]);
|
|
414
|
+
const values = [].map.call(arguments, this._mapCast, this);
|
|
408
415
|
const added = [];
|
|
409
416
|
let type = '';
|
|
410
417
|
if (values[0] instanceof ArraySubdocument) {
|
|
@@ -415,7 +422,7 @@ const methods = {
|
|
|
415
422
|
type = 'ObjectId';
|
|
416
423
|
}
|
|
417
424
|
|
|
418
|
-
const rawValues = utils.isMongooseArray(values) ? values.__array :
|
|
425
|
+
const rawValues = utils.isMongooseArray(values) ? values.__array : values;
|
|
419
426
|
const rawArray = utils.isMongooseArray(this) ? this.__array : this;
|
|
420
427
|
|
|
421
428
|
rawValues.forEach(function(v) {
|
|
@@ -682,10 +689,7 @@ const methods = {
|
|
|
682
689
|
|
|
683
690
|
_checkManualPopulation(this, values);
|
|
684
691
|
|
|
685
|
-
const parent = this[arrayParentSymbol];
|
|
686
692
|
values = [].map.call(values, this._mapCast, this);
|
|
687
|
-
values = this[arraySchemaSymbol].applySetters(values, parent, undefined,
|
|
688
|
-
undefined, { skipDocumentArrayCast: true });
|
|
689
693
|
let ret;
|
|
690
694
|
const atomics = this[arrayAtomicsSymbol];
|
|
691
695
|
this._markModified();
|
|
@@ -711,7 +715,7 @@ const methods = {
|
|
|
711
715
|
'with different `$position`');
|
|
712
716
|
}
|
|
713
717
|
atomic = values;
|
|
714
|
-
ret =
|
|
718
|
+
ret = _basePush.apply(arr, values);
|
|
715
719
|
}
|
|
716
720
|
|
|
717
721
|
this._registerAtomic('$push', atomic);
|
|
@@ -917,7 +921,6 @@ const methods = {
|
|
|
917
921
|
values = arguments;
|
|
918
922
|
} else {
|
|
919
923
|
values = [].map.call(arguments, this._cast, this);
|
|
920
|
-
values = this[arraySchemaSymbol].applySetters(values, this[arrayParentSymbol]);
|
|
921
924
|
}
|
|
922
925
|
|
|
923
926
|
const arr = utils.isMongooseArray(this) ? this.__array : this;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "7.6.
|
|
4
|
+
"version": "7.6.6",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"bson": "^5.5.0",
|
|
23
23
|
"kareem": "2.5.1",
|
|
24
|
-
"mongodb": "5.9.
|
|
24
|
+
"mongodb": "5.9.1",
|
|
25
25
|
"mpath": "0.9.0",
|
|
26
26
|
"mquery": "5.0.0",
|
|
27
27
|
"ms": "2.1.3",
|
|
@@ -93,9 +93,10 @@
|
|
|
93
93
|
"docs:merge:6x": "git merge 6.x",
|
|
94
94
|
"docs:test": "npm run docs:generate && npm run docs:generate:search",
|
|
95
95
|
"docs:view": "node ./scripts/static.js",
|
|
96
|
-
"docs:prepare:publish:stable": "npm run docs:checkout:gh-pages && npm run docs:merge:stable && npm run docs:
|
|
96
|
+
"docs:prepare:publish:stable": "npm run docs:checkout:gh-pages && npm run docs:merge:stable && npm run docs:generate && npm run docs:generate:search",
|
|
97
97
|
"docs:prepare:publish:5x": "npm run docs:checkout:5x && npm run docs:merge:5x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:5x",
|
|
98
98
|
"docs:prepare:publish:6x": "npm run docs:checkout:6x && npm run docs:merge:6x && npm run docs:clean:stable && env DOCS_DEPLOY=true npm run docs:generate && npm run docs:move:6x:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:6x",
|
|
99
|
+
"docs:prepare:publish:7x": "env DOCS_DEPLOY=true npm run docs:generate && npm run docs:checkout:gh-pages && rimraf ./docs/7.x && mv ./tmp ./docs/7.x",
|
|
99
100
|
"docs:check-links": "blc http://127.0.0.1:8089 -ro",
|
|
100
101
|
"lint": "eslint .",
|
|
101
102
|
"lint-js": "eslint . --ext .js --ext .cjs",
|
|
@@ -105,8 +106,9 @@
|
|
|
105
106
|
"prepublishOnly": "npm run build-browser",
|
|
106
107
|
"release": "git pull && git push origin master --tags && npm publish",
|
|
107
108
|
"release-5x": "git pull origin 5.x && git push origin 5.x && git push origin 5.x --tags && npm publish --tag 5x",
|
|
108
|
-
"release-6x": "git pull origin 6.x && git push origin 6.x && git push origin 6.x --tags && npm publish --tag
|
|
109
|
+
"release-6x": "git pull origin 6.x && git push origin 6.x && git push origin 6.x --tags && npm publish --tag 6x",
|
|
109
110
|
"mongo": "node ./tools/repl.js",
|
|
111
|
+
"publish-7x": "npm publish --tag 7x",
|
|
110
112
|
"test": "mocha --exit ./test/*.test.js",
|
|
111
113
|
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
|
|
112
114
|
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
|
package/types/index.d.ts
CHANGED
|
@@ -336,6 +336,7 @@ declare module 'mongoose' {
|
|
|
336
336
|
post<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], options: SchemaPostOptions & SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
337
337
|
post<T = THydratedDocumentType>(method: MongooseQueryOrDocumentMiddleware | MongooseQueryOrDocumentMiddleware[] | RegExp, options: SchemaPostOptions & { document: true, query: false }, fn: PostMiddlewareFunction<T, T>): this;
|
|
338
338
|
// this = Query
|
|
339
|
+
post<T = Query<any, any>>(method: MongooseRawResultQueryMiddleware|MongooseRawResultQueryMiddleware[], fn: PostMiddlewareFunction<T, null | QueryResultType<T> | ModifyResult<QueryResultType<T>>>): this;
|
|
339
340
|
post<T = Query<any, any>>(method: MongooseDefaultQueryMiddleware|MongooseDefaultQueryMiddleware[], fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
|
|
340
341
|
post<T = Query<any, any>>(method: MongooseDistinctQueryMiddleware|MongooseDistinctQueryMiddleware[], options: SchemaPostOptions, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
|
|
341
342
|
post<T = Query<any, any>>(method: MongooseQueryOrDocumentMiddleware | MongooseQueryOrDocumentMiddleware[] | RegExp, options: SchemaPostOptions & { document: false, query: true }, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
|
|
@@ -633,7 +634,7 @@ declare module 'mongoose' {
|
|
|
633
634
|
* { age: 30 }
|
|
634
635
|
* ```
|
|
635
636
|
*/
|
|
636
|
-
export type UpdateQuery<T> = _UpdateQuery<T> & AnyObject;
|
|
637
|
+
export type UpdateQuery<T> = AnyKeys<T> & _UpdateQuery<T> & AnyObject;
|
|
637
638
|
|
|
638
639
|
/**
|
|
639
640
|
* A more strict form of UpdateQuery that enforces updating only
|
package/types/middlewares.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ declare module 'mongoose' {
|
|
|
5
5
|
type MongooseDistinctDocumentMiddleware = 'save' | 'init' | 'validate';
|
|
6
6
|
type MongooseDocumentMiddleware = MongooseDistinctDocumentMiddleware | MongooseQueryAndDocumentMiddleware;
|
|
7
7
|
|
|
8
|
-
type
|
|
8
|
+
type MongooseRawResultQueryMiddleware = 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
|
|
9
|
+
type MongooseDistinctQueryMiddleware = 'count' | 'estimatedDocumentCount' | 'countDocuments' | 'deleteMany' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndReplace' | 'findOneAndRemove' | 'findOneAndUpdate' | 'replaceOne' | 'updateMany';
|
|
10
|
+
|
|
9
11
|
type MongooseDefaultQueryMiddleware = MongooseDistinctQueryMiddleware | 'updateOne' | 'deleteOne';
|
|
10
12
|
type MongooseQueryMiddleware = MongooseDistinctQueryMiddleware | MongooseQueryAndDocumentMiddleware;
|
|
11
13
|
|
package/types/models.d.ts
CHANGED
|
@@ -461,8 +461,9 @@ declare module 'mongoose' {
|
|
|
461
461
|
|
|
462
462
|
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
|
|
463
463
|
validate(): Promise<void>;
|
|
464
|
-
validate(
|
|
465
|
-
validate(
|
|
464
|
+
validate(obj: any): Promise<void>;
|
|
465
|
+
validate(obj: any, pathsOrOptions: PathsToValidate): Promise<void>;
|
|
466
|
+
validate(obj: any, pathsOrOptions: { pathsToSkip?: pathsToSkip }): Promise<void>;
|
|
466
467
|
|
|
467
468
|
/** Watches the underlying collection for changes using [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/). */
|
|
468
469
|
watch<ResultType extends mongodb.Document = any, ChangeType extends mongodb.ChangeStreamDocument = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType, ChangeType>;
|
|
@@ -546,6 +547,10 @@ declare module 'mongoose' {
|
|
|
546
547
|
TRawDocType,
|
|
547
548
|
'findOneAndDelete'
|
|
548
549
|
>;
|
|
550
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
551
|
+
id?: mongodb.ObjectId | any,
|
|
552
|
+
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
553
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
549
554
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
550
555
|
id?: mongodb.ObjectId | any,
|
|
551
556
|
options?: QueryOptions<TRawDocType> | null
|
|
@@ -562,10 +567,6 @@ declare module 'mongoose' {
|
|
|
562
567
|
TRawDocType,
|
|
563
568
|
'findOneAndDelete'
|
|
564
569
|
>;
|
|
565
|
-
findByIdAndRemove<ResultDoc = THydratedDocumentType>(
|
|
566
|
-
id?: mongodb.ObjectId | any,
|
|
567
|
-
options?: QueryOptions<TRawDocType> | null
|
|
568
|
-
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
569
570
|
|
|
570
571
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
571
572
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
@@ -615,6 +616,10 @@ declare module 'mongoose' {
|
|
|
615
616
|
TRawDocType,
|
|
616
617
|
'findOneAndDelete'
|
|
617
618
|
>;
|
|
619
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
620
|
+
filter?: FilterQuery<TRawDocType>,
|
|
621
|
+
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
622
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
618
623
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
619
624
|
filter?: FilterQuery<TRawDocType>,
|
|
620
625
|
options?: QueryOptions<TRawDocType> | null
|
package/types/query.d.ts
CHANGED
|
@@ -217,7 +217,7 @@ declare module 'mongoose' {
|
|
|
217
217
|
allowDiskUse(value: boolean): this;
|
|
218
218
|
|
|
219
219
|
/** Specifies arguments for an `$and` condition. */
|
|
220
|
-
and(array: FilterQuery<
|
|
220
|
+
and(array: FilterQuery<RawDocType>[]): this;
|
|
221
221
|
|
|
222
222
|
/** Specifies the batchSize option. */
|
|
223
223
|
batchSize(val: number): this;
|
|
@@ -265,7 +265,7 @@ declare module 'mongoose' {
|
|
|
265
265
|
comment(val: string): this;
|
|
266
266
|
|
|
267
267
|
/** Specifies this query as a `count` query. */
|
|
268
|
-
count(criteria?: FilterQuery<
|
|
268
|
+
count(criteria?: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
269
269
|
number,
|
|
270
270
|
DocType,
|
|
271
271
|
THelpers,
|
|
@@ -275,7 +275,7 @@ declare module 'mongoose' {
|
|
|
275
275
|
|
|
276
276
|
/** Specifies this query as a `countDocuments` query. */
|
|
277
277
|
countDocuments(
|
|
278
|
-
criteria?: FilterQuery<
|
|
278
|
+
criteria?: FilterQuery<RawDocType>,
|
|
279
279
|
options?: QueryOptions<DocType>
|
|
280
280
|
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments'>;
|
|
281
281
|
|
|
@@ -291,10 +291,10 @@ declare module 'mongoose' {
|
|
|
291
291
|
* collection, regardless of the value of `single`.
|
|
292
292
|
*/
|
|
293
293
|
deleteMany(
|
|
294
|
-
filter?: FilterQuery<
|
|
294
|
+
filter?: FilterQuery<RawDocType>,
|
|
295
295
|
options?: QueryOptions<DocType>
|
|
296
296
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany'>;
|
|
297
|
-
deleteMany(filter: FilterQuery<
|
|
297
|
+
deleteMany(filter: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
298
298
|
any,
|
|
299
299
|
DocType,
|
|
300
300
|
THelpers,
|
|
@@ -309,10 +309,10 @@ declare module 'mongoose' {
|
|
|
309
309
|
* option.
|
|
310
310
|
*/
|
|
311
311
|
deleteOne(
|
|
312
|
-
filter?: FilterQuery<
|
|
312
|
+
filter?: FilterQuery<RawDocType>,
|
|
313
313
|
options?: QueryOptions<DocType>
|
|
314
314
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne'>;
|
|
315
|
-
deleteOne(filter: FilterQuery<
|
|
315
|
+
deleteOne(filter: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
316
316
|
any,
|
|
317
317
|
DocType,
|
|
318
318
|
THelpers,
|
|
@@ -324,7 +324,7 @@ declare module 'mongoose' {
|
|
|
324
324
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
325
325
|
distinct<ReturnType = any>(
|
|
326
326
|
field: string,
|
|
327
|
-
filter?: FilterQuery<
|
|
327
|
+
filter?: FilterQuery<RawDocType>
|
|
328
328
|
): QueryWithHelpers<Array<ReturnType>, DocType, THelpers, RawDocType, 'distinct'>;
|
|
329
329
|
|
|
330
330
|
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
@@ -364,71 +364,71 @@ declare module 'mongoose' {
|
|
|
364
364
|
|
|
365
365
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
366
366
|
find(
|
|
367
|
-
filter: FilterQuery<
|
|
368
|
-
projection?: ProjectionType<
|
|
367
|
+
filter: FilterQuery<RawDocType>,
|
|
368
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
369
369
|
options?: QueryOptions<DocType> | null
|
|
370
370
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
371
371
|
find(
|
|
372
|
-
filter: FilterQuery<
|
|
373
|
-
projection?: ProjectionType<
|
|
372
|
+
filter: FilterQuery<RawDocType>,
|
|
373
|
+
projection?: ProjectionType<RawDocType> | null
|
|
374
374
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
375
375
|
find(
|
|
376
|
-
filter: FilterQuery<
|
|
377
|
-
): QueryWithHelpers<Array<
|
|
376
|
+
filter: FilterQuery<RawDocType>
|
|
377
|
+
): QueryWithHelpers<Array<RawDocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
378
378
|
find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
379
379
|
|
|
380
380
|
/** Declares the query a findOne operation. When executed, returns the first found document. */
|
|
381
381
|
findOne(
|
|
382
|
-
filter?: FilterQuery<
|
|
383
|
-
projection?: ProjectionType<
|
|
382
|
+
filter?: FilterQuery<RawDocType>,
|
|
383
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
384
384
|
options?: QueryOptions<DocType> | null
|
|
385
385
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
386
386
|
findOne(
|
|
387
|
-
filter?: FilterQuery<
|
|
388
|
-
projection?: ProjectionType<
|
|
387
|
+
filter?: FilterQuery<RawDocType>,
|
|
388
|
+
projection?: ProjectionType<RawDocType> | null
|
|
389
389
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
390
390
|
findOne(
|
|
391
|
-
filter?: FilterQuery<
|
|
392
|
-
): QueryWithHelpers<DocType | null,
|
|
391
|
+
filter?: FilterQuery<RawDocType>
|
|
392
|
+
): QueryWithHelpers<DocType | null, RawDocType, THelpers, RawDocType, 'findOne'>;
|
|
393
393
|
|
|
394
394
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
395
395
|
findOneAndDelete(
|
|
396
|
-
filter?: FilterQuery<
|
|
396
|
+
filter?: FilterQuery<RawDocType>,
|
|
397
397
|
options?: QueryOptions<DocType> | null
|
|
398
398
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
399
399
|
|
|
400
400
|
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
401
401
|
findOneAndRemove(
|
|
402
|
-
filter?: FilterQuery<
|
|
402
|
+
filter?: FilterQuery<RawDocType>,
|
|
403
403
|
options?: QueryOptions<DocType> | null
|
|
404
404
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndRemove'>;
|
|
405
405
|
|
|
406
406
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
407
407
|
findOneAndUpdate(
|
|
408
|
-
filter: FilterQuery<
|
|
409
|
-
update: UpdateQuery<
|
|
408
|
+
filter: FilterQuery<RawDocType>,
|
|
409
|
+
update: UpdateQuery<RawDocType>,
|
|
410
410
|
options: QueryOptions<DocType> & { rawResult: true }
|
|
411
411
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
412
412
|
findOneAndUpdate(
|
|
413
|
-
filter: FilterQuery<
|
|
414
|
-
update: UpdateQuery<
|
|
413
|
+
filter: FilterQuery<RawDocType>,
|
|
414
|
+
update: UpdateQuery<RawDocType>,
|
|
415
415
|
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
|
|
416
416
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
417
417
|
findOneAndUpdate(
|
|
418
|
-
filter?: FilterQuery<
|
|
419
|
-
update?: UpdateQuery<
|
|
418
|
+
filter?: FilterQuery<RawDocType>,
|
|
419
|
+
update?: UpdateQuery<RawDocType>,
|
|
420
420
|
options?: QueryOptions<DocType> | null
|
|
421
421
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
422
422
|
|
|
423
423
|
/** Declares the query a findById operation. When executed, returns the document with the given `_id`. */
|
|
424
424
|
findById(
|
|
425
425
|
id: mongodb.ObjectId | any,
|
|
426
|
-
projection?: ProjectionType<
|
|
426
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
427
427
|
options?: QueryOptions<DocType> | null
|
|
428
428
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
429
429
|
findById(
|
|
430
430
|
id: mongodb.ObjectId | any,
|
|
431
|
-
projection?: ProjectionType<
|
|
431
|
+
projection?: ProjectionType<RawDocType> | null
|
|
432
432
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
433
433
|
findById(
|
|
434
434
|
id: mongodb.ObjectId | any
|
|
@@ -443,22 +443,22 @@ declare module 'mongoose' {
|
|
|
443
443
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
444
444
|
findByIdAndUpdate(
|
|
445
445
|
id: mongodb.ObjectId | any,
|
|
446
|
-
update: UpdateQuery<
|
|
446
|
+
update: UpdateQuery<RawDocType>,
|
|
447
447
|
options: QueryOptions<DocType> & { rawResult: true }
|
|
448
448
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
449
449
|
findByIdAndUpdate(
|
|
450
450
|
id: mongodb.ObjectId | any,
|
|
451
|
-
update: UpdateQuery<
|
|
451
|
+
update: UpdateQuery<RawDocType>,
|
|
452
452
|
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
|
|
453
453
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
454
454
|
findByIdAndUpdate(
|
|
455
455
|
id?: mongodb.ObjectId | any,
|
|
456
|
-
update?: UpdateQuery<
|
|
456
|
+
update?: UpdateQuery<RawDocType>,
|
|
457
457
|
options?: QueryOptions<DocType> | null
|
|
458
458
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
459
459
|
findByIdAndUpdate(
|
|
460
460
|
id: mongodb.ObjectId | any,
|
|
461
|
-
update: UpdateQuery<
|
|
461
|
+
update: UpdateQuery<RawDocType>
|
|
462
462
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
463
463
|
|
|
464
464
|
/** Specifies a `$geometry` condition */
|
|
@@ -472,7 +472,7 @@ declare module 'mongoose' {
|
|
|
472
472
|
get(path: string): any;
|
|
473
473
|
|
|
474
474
|
/** Returns the current query filter (also known as conditions) as a POJO. */
|
|
475
|
-
getFilter(): FilterQuery<
|
|
475
|
+
getFilter(): FilterQuery<RawDocType>;
|
|
476
476
|
|
|
477
477
|
/** Gets query options. */
|
|
478
478
|
getOptions(): QueryOptions<DocType>;
|
|
@@ -481,7 +481,7 @@ declare module 'mongoose' {
|
|
|
481
481
|
getPopulatedPaths(): Array<string>;
|
|
482
482
|
|
|
483
483
|
/** Returns the current query filter. Equivalent to `getFilter()`. */
|
|
484
|
-
getQuery(): FilterQuery<
|
|
484
|
+
getQuery(): FilterQuery<RawDocType>;
|
|
485
485
|
|
|
486
486
|
/** Returns the current update operations as a JSON object. */
|
|
487
487
|
getUpdate(): UpdateQuery<DocType> | UpdateWithAggregationPipeline | null;
|
|
@@ -551,7 +551,7 @@ declare module 'mongoose' {
|
|
|
551
551
|
maxTimeMS(ms: number): this;
|
|
552
552
|
|
|
553
553
|
/** Merges another Query or conditions object into this one. */
|
|
554
|
-
merge(source: Query<any, any> | FilterQuery<
|
|
554
|
+
merge(source: Query<any, any> | FilterQuery<RawDocType>): this;
|
|
555
555
|
|
|
556
556
|
/** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
|
|
557
557
|
mod<K = string>(path: K, val: number): this;
|
|
@@ -579,10 +579,10 @@ declare module 'mongoose' {
|
|
|
579
579
|
nin(val: Array<any>): this;
|
|
580
580
|
|
|
581
581
|
/** Specifies arguments for an `$nor` condition. */
|
|
582
|
-
nor(array: Array<FilterQuery<
|
|
582
|
+
nor(array: Array<FilterQuery<RawDocType>>): this;
|
|
583
583
|
|
|
584
584
|
/** Specifies arguments for an `$or` condition. */
|
|
585
|
-
or(array: Array<FilterQuery<
|
|
585
|
+
or(array: Array<FilterQuery<RawDocType>>): this;
|
|
586
586
|
|
|
587
587
|
/**
|
|
588
588
|
* Make this query throw an error if no documents match the given `filter`.
|
|
@@ -639,7 +639,7 @@ declare module 'mongoose' {
|
|
|
639
639
|
* not accept any [atomic](https://www.mongodb.com/docs/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
|
|
640
640
|
*/
|
|
641
641
|
replaceOne(
|
|
642
|
-
filter?: FilterQuery<
|
|
642
|
+
filter?: FilterQuery<RawDocType>,
|
|
643
643
|
replacement?: DocType | AnyObject,
|
|
644
644
|
options?: QueryOptions<DocType> | null
|
|
645
645
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne'>;
|
|
@@ -698,9 +698,9 @@ declare module 'mongoose' {
|
|
|
698
698
|
setOptions(options: QueryOptions<DocType>, overwrite?: boolean): this;
|
|
699
699
|
|
|
700
700
|
/** Sets the query conditions to the provided JSON object. */
|
|
701
|
-
setQuery(val: FilterQuery<
|
|
701
|
+
setQuery(val: FilterQuery<RawDocType> | null): void;
|
|
702
702
|
|
|
703
|
-
setUpdate(update: UpdateQuery<
|
|
703
|
+
setUpdate(update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline): void;
|
|
704
704
|
|
|
705
705
|
/** Specifies an `$size` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
706
706
|
size<K = string>(path: K, val: number): this;
|
|
@@ -738,8 +738,8 @@ declare module 'mongoose' {
|
|
|
738
738
|
* the `multi` option.
|
|
739
739
|
*/
|
|
740
740
|
updateMany(
|
|
741
|
-
filter?: FilterQuery<
|
|
742
|
-
update?: UpdateQuery<
|
|
741
|
+
filter?: FilterQuery<RawDocType>,
|
|
742
|
+
update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
743
743
|
options?: QueryOptions<DocType> | null
|
|
744
744
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany'>;
|
|
745
745
|
|
|
@@ -748,8 +748,8 @@ declare module 'mongoose' {
|
|
|
748
748
|
* `update()`, except it does not support the `multi` or `overwrite` options.
|
|
749
749
|
*/
|
|
750
750
|
updateOne(
|
|
751
|
-
filter?: FilterQuery<
|
|
752
|
-
update?: UpdateQuery<
|
|
751
|
+
filter?: FilterQuery<RawDocType>,
|
|
752
|
+
update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
753
753
|
options?: QueryOptions<DocType> | null
|
|
754
754
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne'>;
|
|
755
755
|
|