mongoose 8.0.1 → 8.0.2
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/README.md +1 -1
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +6 -2
- package/lib/helpers/populate/assignVals.js +3 -2
- package/lib/stateMachine.js +5 -1
- package/lib/types/array/methods/index.js +12 -9
- package/package.json +3 -3
- package/types/document.d.ts +7 -1
- package/types/index.d.ts +2 -1
- package/types/inferschematype.d.ts +42 -5
- package/types/middlewares.d.ts +2 -0
- package/types/models.d.ts +26 -29
- package/types/query.d.ts +44 -44
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
|
|
@@ -32,9 +32,13 @@ const kHasArray = Symbol('mongoose#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,6 @@ module.exports = function assignVals(o) {
|
|
|
144
145
|
|
|
145
146
|
const parts = _path.split('.');
|
|
146
147
|
let cur = docs[i];
|
|
147
|
-
const curPath = parts[0];
|
|
148
148
|
for (let j = 0; j < parts.length - 1; ++j) {
|
|
149
149
|
// If we get to an array with a dotted path, like `arr.foo`, don't set
|
|
150
150
|
// `foo` on the array.
|
|
@@ -160,6 +160,7 @@ module.exports = function assignVals(o) {
|
|
|
160
160
|
// If nothing to set, avoid creating an unnecessary array. Otherwise
|
|
161
161
|
// we'll end up with a single doc in the array with only defaults.
|
|
162
162
|
// See gh-8342, gh-8455
|
|
163
|
+
const curPath = parts.slice(0, j + 1).join('.');
|
|
163
164
|
const schematype = originalSchema._getSchema(curPath);
|
|
164
165
|
if (valueToSet == null && schematype != null && schematype.$isMongooseArray) {
|
|
165
166
|
break;
|
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": "8.0.
|
|
4
|
+
"version": "8.0.2",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -93,10 +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": "
|
|
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",
|
|
100
100
|
"docs:check-links": "blc http://127.0.0.1:8089 -ro",
|
|
101
101
|
"lint": "eslint .",
|
|
102
102
|
"lint-js": "eslint . --ext .js --ext .cjs",
|
package/types/document.d.ts
CHANGED
|
@@ -108,7 +108,13 @@ declare module 'mongoose' {
|
|
|
108
108
|
db: Connection;
|
|
109
109
|
|
|
110
110
|
/** Removes this document from the db. */
|
|
111
|
-
deleteOne(options?: QueryOptions):
|
|
111
|
+
deleteOne(options?: QueryOptions): QueryWithHelpers<
|
|
112
|
+
mongodb.DeleteResult,
|
|
113
|
+
this,
|
|
114
|
+
TQueryHelpers,
|
|
115
|
+
DocType,
|
|
116
|
+
'deleteOne'
|
|
117
|
+
>;
|
|
112
118
|
|
|
113
119
|
/**
|
|
114
120
|
* Takes a populated field and returns it to its unpopulated state. If called with
|
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
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
DefaultTypeKey,
|
|
14
14
|
ObjectIdSchemaDefinition,
|
|
15
15
|
IfEquals,
|
|
16
|
-
DefaultSchemaOptions
|
|
16
|
+
DefaultSchemaOptions,
|
|
17
|
+
IsItRecordAndNotAny
|
|
17
18
|
} from 'mongoose';
|
|
18
19
|
|
|
19
20
|
declare module 'mongoose' {
|
|
@@ -176,6 +177,30 @@ TypeKey
|
|
|
176
177
|
*/
|
|
177
178
|
type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends ReadonlyArray<infer E> ? E : T extends { values: any } ? PathEnumOrString<T['values']> : string;
|
|
178
179
|
|
|
180
|
+
type IsSchemaTypeFromBuiltinClass<T> = T extends (typeof String)
|
|
181
|
+
? true
|
|
182
|
+
: T extends (typeof Number)
|
|
183
|
+
? true
|
|
184
|
+
: T extends (typeof Boolean)
|
|
185
|
+
? true
|
|
186
|
+
: T extends (typeof Buffer)
|
|
187
|
+
? true
|
|
188
|
+
: T extends (typeof Schema.Types.ObjectId)
|
|
189
|
+
? true
|
|
190
|
+
: T extends (typeof Schema.Types.UUID)
|
|
191
|
+
? true
|
|
192
|
+
: T extends (typeof Schema.Types.Decimal128)
|
|
193
|
+
? true
|
|
194
|
+
: T extends Types.ObjectId
|
|
195
|
+
? true
|
|
196
|
+
: T extends Types.Decimal128
|
|
197
|
+
? true
|
|
198
|
+
: T extends Buffer
|
|
199
|
+
? true
|
|
200
|
+
: T extends (typeof Schema.Types.Mixed)
|
|
201
|
+
? true
|
|
202
|
+
: IfEquals<T, Schema.Types.ObjectId, true, false>;
|
|
203
|
+
|
|
179
204
|
/**
|
|
180
205
|
* @summary Resolve path type by returning the corresponding type.
|
|
181
206
|
* @param {PathValueType} PathValueType Document definition path type.
|
|
@@ -189,15 +214,21 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
|
|
|
189
214
|
IfEquals<Item, never, any[], Item extends Schema ?
|
|
190
215
|
// If Item is a schema, infer its type.
|
|
191
216
|
Types.DocumentArray<InferSchemaType<Item>> :
|
|
192
|
-
Item extends Record<TypeKey, any
|
|
217
|
+
Item extends Record<TypeKey, any> ?
|
|
193
218
|
Item[TypeKey] extends Function | String ?
|
|
194
219
|
// If Item has a type key that's a string or a callable, it must be a scalar,
|
|
195
220
|
// so we can directly obtain its path type.
|
|
196
221
|
ObtainDocumentPathType<Item, TypeKey>[] :
|
|
197
222
|
// If the type key isn't callable, then this is an array of objects, in which case
|
|
198
223
|
// we need to call ObtainDocumentType to correctly infer its type.
|
|
199
|
-
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[]:
|
|
200
|
-
|
|
224
|
+
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[] :
|
|
225
|
+
IsSchemaTypeFromBuiltinClass<Item> extends true ?
|
|
226
|
+
ObtainDocumentPathType<Item, TypeKey>[] :
|
|
227
|
+
IsItRecordAndNotAny<Item> extends true ?
|
|
228
|
+
Item extends Record<string, never> ?
|
|
229
|
+
ObtainDocumentPathType<Item, TypeKey>[] :
|
|
230
|
+
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
|
|
231
|
+
ObtainDocumentPathType<Item, TypeKey>[]
|
|
201
232
|
>:
|
|
202
233
|
PathValueType extends ReadonlyArray<infer Item> ?
|
|
203
234
|
IfEquals<Item, never, any[], Item extends Schema ?
|
|
@@ -206,7 +237,13 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
|
|
|
206
237
|
Item[TypeKey] extends Function | String ?
|
|
207
238
|
ObtainDocumentPathType<Item, TypeKey>[] :
|
|
208
239
|
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[]:
|
|
209
|
-
|
|
240
|
+
IsSchemaTypeFromBuiltinClass<Item> extends true ?
|
|
241
|
+
ObtainDocumentPathType<Item, TypeKey>[] :
|
|
242
|
+
IsItRecordAndNotAny<Item> extends true ?
|
|
243
|
+
Item extends Record<string, never> ?
|
|
244
|
+
ObtainDocumentPathType<Item, TypeKey>[] :
|
|
245
|
+
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
|
|
246
|
+
ObtainDocumentPathType<Item, TypeKey>[]
|
|
210
247
|
>:
|
|
211
248
|
PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
|
|
212
249
|
IfEquals<PathValueType, Schema.Types.String> extends true ? PathEnumOrString<Options['enum']> :
|
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 MongooseRawResultQueryMiddleware = 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
|
|
8
9
|
type MongooseDistinctQueryMiddleware = 'estimatedDocumentCount' | 'countDocuments' | 'deleteMany' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndReplace' | '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
|
@@ -26,6 +26,14 @@ declare module 'mongoose' {
|
|
|
26
26
|
interface MongooseBulkWriteOptions {
|
|
27
27
|
skipValidation?: boolean;
|
|
28
28
|
throwOnValidationError?: boolean;
|
|
29
|
+
timestamps?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface MongooseBulkWritePerWriteOptions {
|
|
33
|
+
timestamps?: boolean;
|
|
34
|
+
strict?: boolean;
|
|
35
|
+
session?: ClientSession;
|
|
36
|
+
skipValidation?: boolean;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
interface InsertManyOptions extends
|
|
@@ -183,11 +191,17 @@ declare module 'mongoose' {
|
|
|
183
191
|
* round trip to the MongoDB server.
|
|
184
192
|
*/
|
|
185
193
|
bulkWrite<DocContents = TRawDocType>(
|
|
186
|
-
writes: Array<
|
|
194
|
+
writes: Array<
|
|
195
|
+
mongodb.AnyBulkWriteOperation<
|
|
196
|
+
DocContents extends mongodb.Document ? DocContents : any
|
|
197
|
+
> & MongooseBulkWritePerWriteOptions>,
|
|
187
198
|
options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions & { ordered: false }
|
|
188
199
|
): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[] } }>;
|
|
189
200
|
bulkWrite<DocContents = TRawDocType>(
|
|
190
|
-
writes: Array<
|
|
201
|
+
writes: Array<
|
|
202
|
+
mongodb.AnyBulkWriteOperation<
|
|
203
|
+
DocContents extends mongodb.Document ? DocContents : any
|
|
204
|
+
> & MongooseBulkWritePerWriteOptions>,
|
|
191
205
|
options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions
|
|
192
206
|
): Promise<mongodb.BulkWriteResult>;
|
|
193
207
|
|
|
@@ -452,8 +466,9 @@ declare module 'mongoose' {
|
|
|
452
466
|
|
|
453
467
|
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
|
|
454
468
|
validate(): Promise<void>;
|
|
455
|
-
validate(
|
|
456
|
-
validate(
|
|
469
|
+
validate(obj: any): Promise<void>;
|
|
470
|
+
validate(obj: any, pathsOrOptions: PathsToValidate): Promise<void>;
|
|
471
|
+
validate(obj: any, pathsOrOptions: { pathsToSkip?: pathsToSkip }): Promise<void>;
|
|
457
472
|
|
|
458
473
|
/** Watches the underlying collection for changes using [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/). */
|
|
459
474
|
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>;
|
|
@@ -542,21 +557,9 @@ declare module 'mongoose' {
|
|
|
542
557
|
>;
|
|
543
558
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
544
559
|
id?: mongodb.ObjectId | any,
|
|
545
|
-
options?: QueryOptions<TRawDocType>
|
|
546
|
-
): QueryWithHelpers<ResultDoc
|
|
547
|
-
|
|
548
|
-
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
|
|
549
|
-
findByIdAndRemove<ResultDoc = THydratedDocumentType>(
|
|
550
|
-
id: mongodb.ObjectId | any,
|
|
551
|
-
options: QueryOptions<TRawDocType> & { lean: true }
|
|
552
|
-
): QueryWithHelpers<
|
|
553
|
-
GetLeanResultType<TRawDocType, TRawDocType, 'findOneAndDelete'> | null,
|
|
554
|
-
ResultDoc,
|
|
555
|
-
TQueryHelpers,
|
|
556
|
-
TRawDocType,
|
|
557
|
-
'findOneAndDelete'
|
|
558
|
-
>;
|
|
559
|
-
findByIdAndRemove<ResultDoc = THydratedDocumentType>(
|
|
560
|
+
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
561
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
562
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
560
563
|
id?: mongodb.ObjectId | any,
|
|
561
564
|
options?: QueryOptions<TRawDocType> | null
|
|
562
565
|
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
@@ -578,11 +581,6 @@ declare module 'mongoose' {
|
|
|
578
581
|
update: UpdateQuery<TRawDocType>,
|
|
579
582
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
580
583
|
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate'>;
|
|
581
|
-
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
582
|
-
id: mongodb.ObjectId | any,
|
|
583
|
-
update: UpdateQuery<TRawDocType>,
|
|
584
|
-
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
585
|
-
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate'>;
|
|
586
584
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
587
585
|
id: mongodb.ObjectId | any,
|
|
588
586
|
update: UpdateQuery<TRawDocType>,
|
|
@@ -609,6 +607,10 @@ declare module 'mongoose' {
|
|
|
609
607
|
TRawDocType,
|
|
610
608
|
'findOneAndDelete'
|
|
611
609
|
>;
|
|
610
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
611
|
+
filter?: FilterQuery<TRawDocType>,
|
|
612
|
+
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
613
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
612
614
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
613
615
|
filter?: FilterQuery<TRawDocType>,
|
|
614
616
|
options?: QueryOptions<TRawDocType> | null
|
|
@@ -631,11 +633,6 @@ declare module 'mongoose' {
|
|
|
631
633
|
replacement: TRawDocType | AnyObject,
|
|
632
634
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
633
635
|
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace'>;
|
|
634
|
-
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
635
|
-
filter: FilterQuery<TRawDocType>,
|
|
636
|
-
replacement: TRawDocType | AnyObject,
|
|
637
|
-
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
638
|
-
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace'>;
|
|
639
636
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
640
637
|
filter: FilterQuery<TRawDocType>,
|
|
641
638
|
replacement: TRawDocType | AnyObject,
|
package/types/query.d.ts
CHANGED
|
@@ -212,7 +212,7 @@ declare module 'mongoose' {
|
|
|
212
212
|
allowDiskUse(value: boolean): this;
|
|
213
213
|
|
|
214
214
|
/** Specifies arguments for an `$and` condition. */
|
|
215
|
-
and(array: FilterQuery<
|
|
215
|
+
and(array: FilterQuery<RawDocType>[]): this;
|
|
216
216
|
|
|
217
217
|
/** Specifies the batchSize option. */
|
|
218
218
|
batchSize(val: number): this;
|
|
@@ -261,7 +261,7 @@ declare module 'mongoose' {
|
|
|
261
261
|
|
|
262
262
|
/** Specifies this query as a `countDocuments` query. */
|
|
263
263
|
countDocuments(
|
|
264
|
-
criteria?: FilterQuery<
|
|
264
|
+
criteria?: FilterQuery<RawDocType>,
|
|
265
265
|
options?: QueryOptions<DocType>
|
|
266
266
|
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments'>;
|
|
267
267
|
|
|
@@ -277,10 +277,10 @@ declare module 'mongoose' {
|
|
|
277
277
|
* collection, regardless of the value of `single`.
|
|
278
278
|
*/
|
|
279
279
|
deleteMany(
|
|
280
|
-
filter?: FilterQuery<
|
|
280
|
+
filter?: FilterQuery<RawDocType>,
|
|
281
281
|
options?: QueryOptions<DocType>
|
|
282
282
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany'>;
|
|
283
|
-
deleteMany(filter: FilterQuery<
|
|
283
|
+
deleteMany(filter: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
284
284
|
any,
|
|
285
285
|
DocType,
|
|
286
286
|
THelpers,
|
|
@@ -295,10 +295,10 @@ declare module 'mongoose' {
|
|
|
295
295
|
* option.
|
|
296
296
|
*/
|
|
297
297
|
deleteOne(
|
|
298
|
-
filter?: FilterQuery<
|
|
298
|
+
filter?: FilterQuery<RawDocType>,
|
|
299
299
|
options?: QueryOptions<DocType>
|
|
300
300
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne'>;
|
|
301
|
-
deleteOne(filter: FilterQuery<
|
|
301
|
+
deleteOne(filter: FilterQuery<RawDocType>): QueryWithHelpers<
|
|
302
302
|
any,
|
|
303
303
|
DocType,
|
|
304
304
|
THelpers,
|
|
@@ -310,7 +310,7 @@ declare module 'mongoose' {
|
|
|
310
310
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
311
311
|
distinct<DocKey extends string, ResultType = unknown>(
|
|
312
312
|
field: DocKey,
|
|
313
|
-
filter?: FilterQuery<
|
|
313
|
+
filter?: FilterQuery<RawDocType>
|
|
314
314
|
): QueryWithHelpers<Array<DocKey extends keyof DocType ? Unpacked<DocType[DocKey]> : ResultType>, DocType, THelpers, RawDocType, 'distinct'>;
|
|
315
315
|
|
|
316
316
|
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
@@ -350,65 +350,65 @@ declare module 'mongoose' {
|
|
|
350
350
|
|
|
351
351
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
352
352
|
find(
|
|
353
|
-
filter: FilterQuery<
|
|
354
|
-
projection?: ProjectionType<
|
|
353
|
+
filter: FilterQuery<RawDocType>,
|
|
354
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
355
355
|
options?: QueryOptions<DocType> | null
|
|
356
356
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
357
357
|
find(
|
|
358
|
-
filter: FilterQuery<
|
|
359
|
-
projection?: ProjectionType<
|
|
358
|
+
filter: FilterQuery<RawDocType>,
|
|
359
|
+
projection?: ProjectionType<RawDocType> | null
|
|
360
360
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
361
361
|
find(
|
|
362
|
-
filter: FilterQuery<
|
|
363
|
-
): QueryWithHelpers<Array<
|
|
362
|
+
filter: FilterQuery<RawDocType>
|
|
363
|
+
): QueryWithHelpers<Array<RawDocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
364
364
|
find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>;
|
|
365
365
|
|
|
366
366
|
/** Declares the query a findOne operation. When executed, returns the first found document. */
|
|
367
367
|
findOne(
|
|
368
|
-
filter?: FilterQuery<
|
|
369
|
-
projection?: ProjectionType<
|
|
368
|
+
filter?: FilterQuery<RawDocType>,
|
|
369
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
370
370
|
options?: QueryOptions<DocType> | null
|
|
371
371
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
372
372
|
findOne(
|
|
373
|
-
filter?: FilterQuery<
|
|
374
|
-
projection?: ProjectionType<
|
|
373
|
+
filter?: FilterQuery<RawDocType>,
|
|
374
|
+
projection?: ProjectionType<RawDocType> | null
|
|
375
375
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
376
376
|
findOne(
|
|
377
|
-
filter?: FilterQuery<
|
|
378
|
-
): QueryWithHelpers<DocType | null,
|
|
377
|
+
filter?: FilterQuery<RawDocType>
|
|
378
|
+
): QueryWithHelpers<DocType | null, RawDocType, THelpers, RawDocType, 'findOne'>;
|
|
379
379
|
|
|
380
380
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
381
381
|
findOneAndDelete(
|
|
382
|
-
filter?: FilterQuery<
|
|
382
|
+
filter?: FilterQuery<RawDocType>,
|
|
383
383
|
options?: QueryOptions<DocType> | null
|
|
384
384
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
385
385
|
|
|
386
386
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
387
387
|
findOneAndUpdate(
|
|
388
|
-
filter: FilterQuery<
|
|
389
|
-
update: UpdateQuery<
|
|
388
|
+
filter: FilterQuery<RawDocType>,
|
|
389
|
+
update: UpdateQuery<RawDocType>,
|
|
390
390
|
options: QueryOptions<DocType> & { includeResultMetadata: true }
|
|
391
391
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
392
392
|
findOneAndUpdate(
|
|
393
|
-
filter: FilterQuery<
|
|
394
|
-
update: UpdateQuery<
|
|
393
|
+
filter: FilterQuery<RawDocType>,
|
|
394
|
+
update: UpdateQuery<RawDocType>,
|
|
395
395
|
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
|
|
396
396
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
397
397
|
findOneAndUpdate(
|
|
398
|
-
filter?: FilterQuery<
|
|
399
|
-
update?: UpdateQuery<
|
|
398
|
+
filter?: FilterQuery<RawDocType>,
|
|
399
|
+
update?: UpdateQuery<RawDocType>,
|
|
400
400
|
options?: QueryOptions<DocType> | null
|
|
401
401
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
402
402
|
|
|
403
403
|
/** Declares the query a findById operation. When executed, returns the document with the given `_id`. */
|
|
404
404
|
findById(
|
|
405
405
|
id: mongodb.ObjectId | any,
|
|
406
|
-
projection?: ProjectionType<
|
|
406
|
+
projection?: ProjectionType<RawDocType> | null,
|
|
407
407
|
options?: QueryOptions<DocType> | null
|
|
408
408
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
409
409
|
findById(
|
|
410
410
|
id: mongodb.ObjectId | any,
|
|
411
|
-
projection?: ProjectionType<
|
|
411
|
+
projection?: ProjectionType<RawDocType> | null
|
|
412
412
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne'>;
|
|
413
413
|
findById(
|
|
414
414
|
id: mongodb.ObjectId | any
|
|
@@ -423,22 +423,22 @@ declare module 'mongoose' {
|
|
|
423
423
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
424
424
|
findByIdAndUpdate(
|
|
425
425
|
id: mongodb.ObjectId | any,
|
|
426
|
-
update: UpdateQuery<
|
|
426
|
+
update: UpdateQuery<RawDocType>,
|
|
427
427
|
options: QueryOptions<DocType> & { includeResultMetadata: true }
|
|
428
428
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
429
429
|
findByIdAndUpdate(
|
|
430
430
|
id: mongodb.ObjectId | any,
|
|
431
|
-
update: UpdateQuery<
|
|
431
|
+
update: UpdateQuery<RawDocType>,
|
|
432
432
|
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
|
|
433
433
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
434
434
|
findByIdAndUpdate(
|
|
435
435
|
id?: mongodb.ObjectId | any,
|
|
436
|
-
update?: UpdateQuery<
|
|
436
|
+
update?: UpdateQuery<RawDocType>,
|
|
437
437
|
options?: QueryOptions<DocType> | null
|
|
438
438
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
439
439
|
findByIdAndUpdate(
|
|
440
440
|
id: mongodb.ObjectId | any,
|
|
441
|
-
update: UpdateQuery<
|
|
441
|
+
update: UpdateQuery<RawDocType>
|
|
442
442
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate'>;
|
|
443
443
|
|
|
444
444
|
/** Specifies a `$geometry` condition */
|
|
@@ -452,7 +452,7 @@ declare module 'mongoose' {
|
|
|
452
452
|
get(path: string): any;
|
|
453
453
|
|
|
454
454
|
/** Returns the current query filter (also known as conditions) as a POJO. */
|
|
455
|
-
getFilter(): FilterQuery<
|
|
455
|
+
getFilter(): FilterQuery<RawDocType>;
|
|
456
456
|
|
|
457
457
|
/** Gets query options. */
|
|
458
458
|
getOptions(): QueryOptions<DocType>;
|
|
@@ -461,7 +461,7 @@ declare module 'mongoose' {
|
|
|
461
461
|
getPopulatedPaths(): Array<string>;
|
|
462
462
|
|
|
463
463
|
/** Returns the current query filter. Equivalent to `getFilter()`. */
|
|
464
|
-
getQuery(): FilterQuery<
|
|
464
|
+
getQuery(): FilterQuery<RawDocType>;
|
|
465
465
|
|
|
466
466
|
/** Returns the current update operations as a JSON object. */
|
|
467
467
|
getUpdate(): UpdateQuery<DocType> | UpdateWithAggregationPipeline | null;
|
|
@@ -531,7 +531,7 @@ declare module 'mongoose' {
|
|
|
531
531
|
maxTimeMS(ms: number): this;
|
|
532
532
|
|
|
533
533
|
/** Merges another Query or conditions object into this one. */
|
|
534
|
-
merge(source: Query<any, any> | FilterQuery<
|
|
534
|
+
merge(source: Query<any, any> | FilterQuery<RawDocType>): this;
|
|
535
535
|
|
|
536
536
|
/** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
|
|
537
537
|
mod<K = string>(path: K, val: number): this;
|
|
@@ -559,10 +559,10 @@ declare module 'mongoose' {
|
|
|
559
559
|
nin(val: Array<any>): this;
|
|
560
560
|
|
|
561
561
|
/** Specifies arguments for an `$nor` condition. */
|
|
562
|
-
nor(array: Array<FilterQuery<
|
|
562
|
+
nor(array: Array<FilterQuery<RawDocType>>): this;
|
|
563
563
|
|
|
564
564
|
/** Specifies arguments for an `$or` condition. */
|
|
565
|
-
or(array: Array<FilterQuery<
|
|
565
|
+
or(array: Array<FilterQuery<RawDocType>>): this;
|
|
566
566
|
|
|
567
567
|
/**
|
|
568
568
|
* Make this query throw an error if no documents match the given `filter`.
|
|
@@ -619,7 +619,7 @@ declare module 'mongoose' {
|
|
|
619
619
|
* not accept any [atomic](https://www.mongodb.com/docs/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
|
|
620
620
|
*/
|
|
621
621
|
replaceOne(
|
|
622
|
-
filter?: FilterQuery<
|
|
622
|
+
filter?: FilterQuery<RawDocType>,
|
|
623
623
|
replacement?: DocType | AnyObject,
|
|
624
624
|
options?: QueryOptions<DocType> | null
|
|
625
625
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne'>;
|
|
@@ -678,9 +678,9 @@ declare module 'mongoose' {
|
|
|
678
678
|
setOptions(options: QueryOptions<DocType>, overwrite?: boolean): this;
|
|
679
679
|
|
|
680
680
|
/** Sets the query conditions to the provided JSON object. */
|
|
681
|
-
setQuery(val: FilterQuery<
|
|
681
|
+
setQuery(val: FilterQuery<RawDocType> | null): void;
|
|
682
682
|
|
|
683
|
-
setUpdate(update: UpdateQuery<
|
|
683
|
+
setUpdate(update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline): void;
|
|
684
684
|
|
|
685
685
|
/** Specifies an `$size` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
686
686
|
size<K = string>(path: K, val: number): this;
|
|
@@ -718,8 +718,8 @@ declare module 'mongoose' {
|
|
|
718
718
|
* the `multi` option.
|
|
719
719
|
*/
|
|
720
720
|
updateMany(
|
|
721
|
-
filter?: FilterQuery<
|
|
722
|
-
update?: UpdateQuery<
|
|
721
|
+
filter?: FilterQuery<RawDocType>,
|
|
722
|
+
update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
723
723
|
options?: QueryOptions<DocType> | null
|
|
724
724
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany'>;
|
|
725
725
|
|
|
@@ -728,8 +728,8 @@ declare module 'mongoose' {
|
|
|
728
728
|
* `update()`, except it does not support the `multi` or `overwrite` options.
|
|
729
729
|
*/
|
|
730
730
|
updateOne(
|
|
731
|
-
filter?: FilterQuery<
|
|
732
|
-
update?: UpdateQuery<
|
|
731
|
+
filter?: FilterQuery<RawDocType>,
|
|
732
|
+
update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
733
733
|
options?: QueryOptions<DocType> | null
|
|
734
734
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne'>;
|
|
735
735
|
|