@datanimbus/mongoose 6.13.13 → 9.13.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 +80 -70
- package/eslint.config.mjs +202 -0
- package/index.js +2 -1
- package/lib/aggregate.js +276 -174
- package/lib/cast/bigint.js +46 -0
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/decimal128.js +4 -1
- package/lib/cast/double.js +56 -0
- package/lib/cast/int32.js +42 -0
- package/lib/cast/number.js +6 -6
- package/lib/cast/objectid.js +3 -3
- package/lib/cast/string.js +3 -3
- package/lib/cast/uuid.js +35 -0
- package/lib/cast.js +100 -92
- package/lib/collection.js +31 -22
- package/lib/connection.js +792 -507
- package/lib/constants.js +73 -0
- package/lib/cursor/{AggregationCursor.js → aggregationCursor.js} +205 -52
- package/lib/cursor/changeStream.js +218 -0
- package/lib/cursor/queryCursor.js +676 -0
- package/lib/defaults/schemaDefaultsCache.js +62 -0
- package/lib/document.js +2419 -1306
- package/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
- package/lib/drivers/node-mongodb-native/collection.js +101 -135
- package/lib/drivers/node-mongodb-native/connection.js +386 -28
- package/lib/drivers/node-mongodb-native/index.js +3 -5
- package/lib/error/browserMissingSchema.js +5 -4
- package/lib/error/bulkSaveIncompleteError.js +44 -0
- package/lib/error/cast.js +30 -21
- package/lib/error/createCollectionsError.js +26 -0
- package/lib/error/divergentArray.js +11 -9
- package/lib/error/eachAsyncMultiError.js +2 -2
- package/lib/error/index.js +38 -29
- package/lib/error/invalidSchemaOption.js +32 -0
- package/lib/error/messages.js +4 -3
- package/lib/error/missingSchema.js +8 -6
- package/lib/error/notFound.js +7 -5
- package/lib/error/objectExpected.js +9 -8
- package/lib/error/objectParameter.js +12 -11
- package/lib/error/overwriteModel.js +7 -6
- package/lib/error/parallelSave.js +11 -8
- package/lib/error/parallelValidate.js +9 -7
- package/lib/error/serverSelection.js +1 -0
- package/lib/error/setOptionError.js +11 -9
- package/lib/error/strict.js +12 -10
- package/lib/error/strictPopulate.js +11 -9
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +11 -17
- package/lib/error/validator.js +9 -8
- package/lib/error/version.js +12 -10
- package/lib/filters/operators.js +8 -0
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
- package/lib/helpers/buildMiddlewareFilter.js +42 -0
- package/lib/helpers/clone.js +121 -35
- package/lib/helpers/common.js +7 -7
- package/lib/helpers/cursor/eachAsync.js +14 -11
- package/lib/helpers/cursor/waitForInitialization.js +17 -0
- package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +36 -0
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +9 -6
- package/lib/helpers/discriminator/getDiscriminatorByKey.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorValueFromFilter.js +30 -0
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +41 -9
- package/lib/helpers/document/applyDefaults.js +82 -14
- package/lib/helpers/document/applyTimestamps.js +106 -0
- package/lib/helpers/document/applyVirtuals.js +147 -0
- package/lib/helpers/document/cleanModifiedSubpaths.js +14 -4
- package/lib/helpers/document/compile.js +20 -15
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +38 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +6 -3
- package/lib/helpers/document/handleSpreadDoc.js +2 -1
- package/lib/helpers/document/isInPathsToSave.js +24 -0
- package/lib/helpers/document/toObjectRecursive.js +49 -0
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +11 -20
- package/lib/helpers/getInheritedProperty.js +28 -0
- package/lib/helpers/getOwnProperty.js +19 -0
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/getRelatedIndexes.js +8 -4
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isIndexEqual.js +13 -12
- package/lib/helpers/indexes/isIndexSpecEqual.js +32 -0
- package/lib/helpers/indexes/isTimeseriesIndex.js +16 -0
- package/lib/helpers/isBsonType.js +3 -6
- package/lib/helpers/isMongooseDocument.js +24 -0
- package/lib/helpers/isMongooseObject.js +6 -4
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isPOJO.js +12 -0
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +41 -0
- package/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
- package/lib/helpers/model/applyHooks.js +72 -54
- package/lib/helpers/model/applyMethods.js +3 -3
- package/lib/helpers/model/applyStaticHooks.js +20 -50
- package/lib/helpers/model/castBulkWrite.js +278 -172
- package/lib/helpers/model/decorateBulkWriteResult.js +8 -0
- package/lib/helpers/model/discriminator.js +77 -21
- package/lib/helpers/omitUndefined.js +20 -0
- package/lib/helpers/parallelLimit.js +61 -34
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pathTrie.js +167 -0
- package/lib/helpers/pluralize.js +5 -4
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +12 -7
- package/lib/helpers/populate/assignVals.js +46 -21
- package/lib/helpers/populate/createPopulateQueryFilter.js +13 -5
- package/lib/helpers/populate/getModelsMapForPopulate.js +250 -108
- package/lib/helpers/populate/getSchemaTypes.js +27 -30
- package/lib/helpers/populate/getVirtual.js +31 -0
- package/lib/helpers/populate/markArraySubdocsPopulated.js +6 -4
- package/lib/helpers/populate/modelNamesFromRefPath.js +11 -5
- package/lib/helpers/populate/removeDeselectedForeignField.js +3 -2
- package/lib/helpers/populate/setInheritedReadOptions.js +21 -0
- package/lib/helpers/populate/setPopulatedVirtualValue.js +33 -0
- package/lib/helpers/populate/splitPopulateQuery.js +81 -0
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +7 -2
- package/lib/helpers/projection/applyProjection.js +8 -2
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isExclusive.js +8 -6
- package/lib/helpers/projection/isInclusive.js +2 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isPathSelectedInclusive.js +1 -11
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/projection/parseProjection.js +9 -4
- package/lib/helpers/query/applyGlobalOption.js +9 -9
- package/lib/helpers/query/cast$expr.js +52 -23
- package/lib/helpers/query/castFilterPath.js +22 -22
- package/lib/helpers/query/castUpdate.js +207 -79
- package/lib/helpers/query/cloneMongooseOptions.js +44 -0
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +27 -13
- package/lib/helpers/query/handleImmutable.js +18 -2
- package/lib/helpers/query/handleReadPreferenceAliases.js +23 -0
- package/lib/helpers/query/sanitizeFilter.js +3 -2
- package/lib/helpers/query/selectPopulatedFields.js +13 -0
- package/lib/helpers/query/validOps.js +1 -22
- package/lib/helpers/schema/applyPlugins.js +2 -2
- package/lib/helpers/schema/applyReadConcern.js +20 -0
- package/lib/helpers/schema/applyWriteConcern.js +12 -3
- package/lib/helpers/schema/cleanPositionalOperators.js +5 -3
- package/lib/helpers/schema/getIndexes.js +20 -13
- package/lib/helpers/schema/getKeysInSchemaOrder.js +13 -16
- package/lib/helpers/schema/getPath.js +11 -3
- package/lib/helpers/schema/getSubdocumentStrictValue.js +32 -0
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/idGetter.js +7 -2
- package/lib/helpers/schema/merge.js +9 -1
- package/lib/helpers/schematype/getConditionalHandler.js +23 -0
- package/lib/helpers/schematype/handleImmutable.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +85 -43
- package/lib/helpers/symbols.js +4 -4
- package/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
- package/lib/helpers/timestamps/setupTimestamps.js +69 -37
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/applyTimestampsToUpdate.js +53 -37
- package/lib/helpers/update/castArrayFilters.js +68 -29
- package/lib/helpers/update/decorateUpdateWithVersionKey.js +35 -0
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/update/removeUnusedArrayFilters.js +11 -2
- package/lib/helpers/updateValidators.js +87 -128
- package/lib/index.js +6 -1320
- package/lib/internal.js +7 -1
- package/lib/model.js +2587 -2618
- package/lib/modifiedPathsSnapshot.js +9 -0
- package/lib/mongoose.js +1456 -0
- package/lib/options/saveOptions.js +2 -0
- package/lib/options/{SchemaArrayOptions.js → schemaArrayOptions.js} +16 -5
- package/lib/options/{SchemaBufferOptions.js → schemaBufferOptions.js} +2 -2
- package/lib/options/{SchemaDateOptions.js → schemaDateOptions.js} +1 -1
- package/lib/options/{SchemaDocumentArrayOptions.js → schemaDocumentArrayOptions.js} +24 -1
- package/lib/options/{SchemaMapOptions.js → schemaMapOptions.js} +1 -1
- package/lib/options/{SchemaNumberOptions.js → schemaNumberOptions.js} +5 -5
- package/lib/options/{SchemaObjectIdOptions.js → schemaObjectIdOptions.js} +4 -4
- package/lib/options/{SchemaStringOptions.js → schemaStringOptions.js} +10 -10
- package/lib/options/schemaSubdocumentOptions.js +89 -0
- package/lib/options/{SchemaTypeOptions.js → schemaTypeOptions.js} +28 -14
- package/lib/options/schemaUnionOptions.js +32 -0
- package/lib/options/{VirtualOptions.js → virtualOptions.js} +13 -13
- package/lib/options.js +4 -1
- package/lib/plugins/index.js +0 -2
- package/lib/plugins/saveSubdocs.js +85 -50
- package/lib/plugins/sharding.js +43 -15
- package/lib/plugins/trackTransaction.js +46 -34
- package/lib/query.js +1844 -1909
- package/lib/{queryhelpers.js → queryHelpers.js} +184 -81
- package/lib/schema/array.js +229 -169
- package/lib/schema/bigint.js +281 -0
- package/lib/schema/boolean.js +90 -26
- package/lib/schema/buffer.js +119 -50
- package/lib/schema/date.js +102 -38
- package/lib/schema/decimal128.js +88 -37
- package/lib/schema/{documentarray.js → documentArray.js} +259 -151
- package/lib/schema/documentArrayElement.js +180 -0
- package/lib/schema/double.js +244 -0
- package/lib/schema/index.js +12 -19
- package/lib/schema/int32.js +288 -0
- package/lib/schema/map.js +129 -20
- package/lib/schema/mixed.js +40 -26
- package/lib/schema/number.js +128 -51
- package/lib/schema/{objectid.js → objectId.js} +89 -47
- package/lib/schema/operators/exists.js +1 -1
- package/lib/schema/operators/geospatial.js +2 -2
- package/lib/schema/operators/text.js +4 -4
- package/lib/schema/string.js +125 -66
- package/lib/schema/subdocument.js +443 -0
- package/lib/schema/symbols.js +2 -0
- package/lib/schema/union.js +167 -0
- package/lib/schema/uuid.js +90 -120
- package/lib/schema.js +1267 -388
- package/lib/{schematype.js → schemaType.js} +481 -246
- package/lib/standardSchema/convertErrorToIssues.js +20 -0
- package/lib/{statemachine.js → stateMachine.js} +66 -17
- package/lib/tracing.js +38 -0
- package/lib/types/array/index.js +13 -10
- package/lib/types/array/methods/index.js +243 -63
- package/lib/types/{ArraySubdocument.js → arraySubdocument.js} +35 -14
- package/lib/types/buffer.js +31 -14
- package/lib/types/decimal128.js +1 -1
- package/lib/types/{DocumentArray → documentArray}/index.js +13 -13
- package/lib/types/{DocumentArray → documentArray}/methods/index.js +197 -31
- package/lib/types/double.js +13 -0
- package/lib/types/index.js +5 -2
- package/lib/types/map.js +62 -25
- package/lib/types/objectid.js +2 -2
- package/lib/types/subdocument.js +79 -58
- package/lib/types/uuid.js +13 -0
- package/lib/utils.js +201 -155
- package/lib/{validoptions.js → validOptions.js} +10 -2
- package/lib/{virtualtype.js → virtualType.js} +47 -18
- package/package.json +75 -92
- package/types/aggregate.d.ts +31 -7
- package/types/augmentations.d.ts +2 -2
- package/types/collection.d.ts +21 -16
- package/types/connection.d.ts +82 -27
- package/types/cursor.d.ts +15 -10
- package/types/document.d.ts +137 -56
- package/types/error.d.ts +11 -6
- package/types/expressions.d.ts +33 -2
- package/types/index.d.ts +805 -190
- package/types/indexes.d.ts +85 -13
- package/types/inferhydrateddoctype.d.ts +151 -0
- package/types/inferrawdoctype.d.ts +201 -0
- package/types/inferschematype.d.ts +287 -128
- package/types/middlewares.d.ts +50 -7
- package/types/models.d.ts +1555 -268
- package/types/mongooseoptions.d.ts +56 -7
- package/types/pipelinestage.d.ts +42 -3
- package/types/populate.d.ts +63 -1
- package/types/query.d.ts +592 -255
- package/types/schemaoptions.d.ts +78 -12
- package/types/schematypes.d.ts +254 -65
- package/types/session.d.ts +0 -4
- package/types/tracing.d.ts +10 -0
- package/types/types.d.ts +25 -8
- package/types/utility.d.ts +329 -30
- package/types/validation.d.ts +19 -14
- package/types/virtuals.d.ts +10 -10
- package/.eslintrc.js +0 -232
- package/.mocharc.yml +0 -4
- package/browser.js +0 -8
- package/lgtm.yml +0 -12
- package/lib/browser.js +0 -158
- package/lib/browserDocument.js +0 -101
- package/lib/cursor/ChangeStream.js +0 -154
- package/lib/cursor/QueryCursor.js +0 -545
- package/lib/document_provider.js +0 -30
- package/lib/drivers/browser/ReadPreference.js +0 -7
- package/lib/drivers/browser/binary.js +0 -14
- package/lib/drivers/browser/decimal128.js +0 -7
- package/lib/drivers/browser/index.js +0 -16
- package/lib/drivers/browser/objectid.js +0 -29
- package/lib/drivers/node-mongodb-native/ReadPreference.js +0 -47
- package/lib/drivers/node-mongodb-native/binary.js +0 -10
- package/lib/drivers/node-mongodb-native/decimal128.js +0 -7
- package/lib/drivers/node-mongodb-native/objectid.js +0 -16
- package/lib/error/disconnected.js +0 -33
- package/lib/helpers/printStrictQueryWarning.js +0 -11
- package/lib/helpers/promiseOrCallback.js +0 -55
- package/lib/helpers/query/applyQueryMiddleware.js +0 -79
- package/lib/helpers/query/completeMany.js +0 -52
- package/lib/helpers/query/wrapThunk.js +0 -36
- package/lib/options/SchemaSubdocumentOptions.js +0 -42
- package/lib/options/removeOptions.js +0 -14
- package/lib/plugins/removeSubdocs.js +0 -31
- package/lib/plugins/validateBeforeSave.js +0 -45
- package/lib/promise_provider.js +0 -49
- package/lib/schema/DocumentArrayElement.js +0 -100
- package/lib/schema/SubdocumentPath.js +0 -369
- package/scripts/build-browser.js +0 -18
- package/scripts/create-tarball.js +0 -7
- package/scripts/generateSearch.js +0 -154
- package/scripts/tsc-diagnostics-check.js +0 -15
- package/tools/auth.js +0 -31
- package/tools/repl.js +0 -35
- package/tools/sharded.js +0 -46
- package/tsconfig.json +0 -9
- /package/lib/{connectionstate.js → connectionState.js} +0 -0
- /package/lib/helpers/populate/{SkipPopulateValue.js → skipPopulateValue.js} +0 -0
- /package/lib/options/{PopulateOptions.js → populateOptions.js} +0 -0
- /package/lib/types/{DocumentArray → documentArray}/isMongooseDocumentArray.js +0 -0
package/types/models.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
2
|
import mongodb = require('mongodb');
|
|
3
|
+
import { StandardSchemaV1 as StandardSchemaV1Spec, StandardTypedV1 as StandardTypedV1Spec } from '@standard-schema/spec';
|
|
3
4
|
|
|
4
5
|
export interface DiscriminatorOptions {
|
|
5
6
|
value?: string | number | ObjectId;
|
|
@@ -11,91 +12,86 @@ declare module 'mongoose' {
|
|
|
11
12
|
|
|
12
13
|
export interface AcceptsDiscriminator {
|
|
13
14
|
/** Adds a discriminator type. */
|
|
14
|
-
discriminator<D>(
|
|
15
|
-
|
|
15
|
+
discriminator<D>(
|
|
16
|
+
name: string | number,
|
|
17
|
+
schema: Schema,
|
|
18
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
19
|
+
): Model<D>;
|
|
20
|
+
discriminator<T, U>(
|
|
21
|
+
name: string | number,
|
|
22
|
+
schema: Schema<T, U>,
|
|
23
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
24
|
+
): Model<U>;
|
|
16
25
|
}
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
export type MongooseBulkWriteResult = mongodb.BulkWriteResult & {
|
|
28
|
+
mongoose?: {
|
|
29
|
+
validationErrors: Error[],
|
|
30
|
+
results: Array<Error | mongodb.WriteError | null>
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface MongooseBulkWriteOptions extends mongodb.BulkWriteOptions {
|
|
35
|
+
session?: ClientSession;
|
|
19
36
|
skipValidation?: boolean;
|
|
20
|
-
strict?: boolean;
|
|
21
|
-
timestamps?: boolean | 'throw';
|
|
22
37
|
throwOnValidationError?: boolean;
|
|
38
|
+
strict?: boolean | 'throw';
|
|
39
|
+
/** When false, do not add timestamps to documents. Can be overridden at the operation level. */
|
|
40
|
+
timestamps?: boolean;
|
|
41
|
+
/** set to `false` to skip all user-defined middleware, or `{ pre: false }` / `{ post: false }` to skip only pre or post hooks */
|
|
42
|
+
middleware?: boolean | SkipMiddlewareOptions;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface MongooseBulkSaveOptions extends mongodb.BulkWriteOptions {
|
|
46
|
+
timestamps?: boolean;
|
|
47
|
+
session?: ClientSession;
|
|
48
|
+
validateBeforeSave?: boolean;
|
|
49
|
+
/** set to `false` to skip all user-defined middleware, or `{ pre: false }` / `{ post: false }` to skip only pre or post hooks */
|
|
50
|
+
middleware?: boolean | SkipMiddlewareOptions;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated use AnyBulkWriteOperation instead
|
|
55
|
+
*/
|
|
56
|
+
interface MongooseBulkWritePerWriteOptions {
|
|
57
|
+
timestamps?: boolean;
|
|
58
|
+
strict?: boolean | 'throw';
|
|
59
|
+
session?: ClientSession;
|
|
60
|
+
skipValidation?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface HydrateOptions {
|
|
64
|
+
setters?: boolean;
|
|
65
|
+
hydratedPopulatedDocs?: boolean;
|
|
66
|
+
virtuals?: boolean;
|
|
67
|
+
strict?: boolean | 'throw';
|
|
23
68
|
}
|
|
24
69
|
|
|
25
70
|
interface InsertManyOptions extends
|
|
26
71
|
PopulateOption,
|
|
27
72
|
SessionOption {
|
|
28
73
|
limit?: number;
|
|
74
|
+
// @deprecated, use includeResultMetadata instead
|
|
29
75
|
rawResult?: boolean;
|
|
76
|
+
includeResultMetadata?: boolean;
|
|
30
77
|
ordered?: boolean;
|
|
31
78
|
lean?: boolean;
|
|
32
79
|
throwOnValidationError?: boolean;
|
|
80
|
+
/** set to `false` to skip all user-defined middleware, or `{ pre: false }` / `{ post: false }` to skip only pre or post hooks */
|
|
81
|
+
middleware?: boolean | SkipMiddlewareOptions;
|
|
82
|
+
timestamps?: boolean | QueryTimestampsConfig;
|
|
33
83
|
}
|
|
34
84
|
|
|
35
|
-
|
|
36
|
-
insertedIds: {
|
|
37
|
-
[key: number]: InferId<T>;
|
|
38
|
-
};
|
|
85
|
+
interface InsertManyResult<T> extends mongodb.InsertManyResult<T> {
|
|
39
86
|
mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> };
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
type UpdateWriteOpResult = mongodb.UpdateResult;
|
|
43
|
-
|
|
44
|
-
interface MapReduceOptions<T, K, R> {
|
|
45
|
-
map: Function | string;
|
|
46
|
-
reduce: (key: K, vals: T[]) => R;
|
|
47
|
-
/** query filter object. */
|
|
48
|
-
query?: any;
|
|
49
|
-
/** sort input objects using this key */
|
|
50
|
-
sort?: any;
|
|
51
|
-
/** max number of documents */
|
|
52
|
-
limit?: number;
|
|
53
|
-
/** keep temporary data default: false */
|
|
54
|
-
keeptemp?: boolean;
|
|
55
|
-
/** finalize function */
|
|
56
|
-
finalize?: (key: K, val: R) => R;
|
|
57
|
-
/** scope variables exposed to map/reduce/finalize during execution */
|
|
58
|
-
scope?: any;
|
|
59
|
-
/** it is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X default: false */
|
|
60
|
-
jsMode?: boolean;
|
|
61
|
-
/** provide statistics on job execution time. default: false */
|
|
62
|
-
verbose?: boolean;
|
|
63
|
-
readPreference?: string;
|
|
64
|
-
/** sets the output target for the map reduce job. default: {inline: 1} */
|
|
65
|
-
out?: {
|
|
66
|
-
/** the results are returned in an array */
|
|
67
|
-
inline?: number;
|
|
68
|
-
/**
|
|
69
|
-
* {replace: 'collectionName'} add the results to collectionName: the
|
|
70
|
-
* results replace the collection
|
|
71
|
-
*/
|
|
72
|
-
replace?: string;
|
|
73
|
-
/**
|
|
74
|
-
* {reduce: 'collectionName'} add the results to collectionName: if
|
|
75
|
-
* dups are detected, uses the reducer / finalize functions
|
|
76
|
-
*/
|
|
77
|
-
reduce?: string;
|
|
78
|
-
/**
|
|
79
|
-
* {merge: 'collectionName'} add the results to collectionName: if
|
|
80
|
-
* dups exist the new docs overwrite the old
|
|
81
|
-
*/
|
|
82
|
-
merge?: string;
|
|
83
|
-
};
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/** the maximum distance from the point near that a result can be */
|
|
90
|
-
maxDistance: number;
|
|
91
|
-
/** The maximum number of results to return */
|
|
92
|
-
limit?: number;
|
|
93
|
-
/** return the raw object instead of the Mongoose Model */
|
|
94
|
-
lean?: boolean;
|
|
95
|
-
}
|
|
89
|
+
type UpdateWriteOpResult = mongodb.UpdateResult;
|
|
90
|
+
type UpdateResult = mongodb.UpdateResult;
|
|
91
|
+
type DeleteResult = mongodb.DeleteResult;
|
|
96
92
|
|
|
97
93
|
interface ModifyResult<T> {
|
|
98
|
-
value: Require_id<T
|
|
94
|
+
value: Default__v<Require_id<T>> | null;
|
|
99
95
|
/** see https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject */
|
|
100
96
|
lastErrorObject?: {
|
|
101
97
|
updatedExisting?: boolean;
|
|
@@ -113,43 +109,159 @@ declare module 'mongoose' {
|
|
|
113
109
|
*/
|
|
114
110
|
type pathsToValidate = PathsToValidate;
|
|
115
111
|
|
|
112
|
+
export import StandardTypedV1 = StandardTypedV1Spec;
|
|
113
|
+
export import StandardSchemaV1 = StandardSchemaV1Spec;
|
|
114
|
+
|
|
116
115
|
interface SaveOptions extends
|
|
117
116
|
SessionOption {
|
|
118
117
|
checkKeys?: boolean;
|
|
119
118
|
j?: boolean;
|
|
119
|
+
/** An array of paths that tell mongoose to only validate and save the paths in `pathsToSave`. */
|
|
120
|
+
pathsToSave?: string[];
|
|
120
121
|
safe?: boolean | WriteConcern;
|
|
121
122
|
timestamps?: boolean | QueryTimestampsConfig;
|
|
122
123
|
validateBeforeSave?: boolean;
|
|
123
124
|
validateModifiedOnly?: boolean;
|
|
124
125
|
w?: number | string;
|
|
125
126
|
wtimeout?: number;
|
|
127
|
+
/** set to `false` to skip all user-defined middleware, or `{ pre: false }` / `{ post: false }` to skip only pre or post hooks */
|
|
128
|
+
middleware?: boolean | SkipMiddlewareOptions;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface CreateOptions extends SaveOptions {
|
|
132
|
+
ordered?: boolean;
|
|
133
|
+
aggregateErrors?: boolean;
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
interface RemoveOptions extends SessionOption, Omit<mongodb.DeleteOptions, 'session'> {}
|
|
129
137
|
|
|
138
|
+
interface MongooseBulkWritePerOperationOptions {
|
|
139
|
+
/** Skip validation for this operation. */
|
|
140
|
+
skipValidation?: boolean;
|
|
141
|
+
/** When false, do not add timestamps. When true, overrides the `timestamps` option set in the `bulkWrite` options. */
|
|
142
|
+
timestamps?: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface MongooseBulkUpdatePerOperationOptions extends MongooseBulkWritePerOperationOptions {
|
|
146
|
+
/** When true, allows updating fields that are marked as `immutable` in the schema. */
|
|
147
|
+
overwriteImmutable?: boolean;
|
|
148
|
+
/** When false, do not set default values on insert. */
|
|
149
|
+
setDefaultsOnInsert?: boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type InsertOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
153
|
+
mongodb.InsertOneModel<TSchema> & MongooseBulkWritePerOperationOptions;
|
|
154
|
+
|
|
155
|
+
export type ReplaceOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
156
|
+
Omit<mongodb.ReplaceOneModel<TSchema>, 'filter'> &
|
|
157
|
+
{ filter: QueryFilter<TSchema> } &
|
|
158
|
+
MongooseBulkUpdatePerOperationOptions;
|
|
159
|
+
|
|
160
|
+
export type UpdateOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
161
|
+
Omit<mongodb.UpdateOneModel<TSchema>, 'filter' | 'update'> &
|
|
162
|
+
{
|
|
163
|
+
filter: QueryFilter<TSchema>;
|
|
164
|
+
update: UpdateQuery<TSchema> | UpdateWithAggregationPipeline;
|
|
165
|
+
} &
|
|
166
|
+
MongooseBulkUpdatePerOperationOptions;
|
|
167
|
+
|
|
168
|
+
export type UpdateManyModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
169
|
+
Omit<mongodb.UpdateManyModel<TSchema>, 'filter' | 'update'> &
|
|
170
|
+
{
|
|
171
|
+
filter: QueryFilter<TSchema>;
|
|
172
|
+
update: UpdateQuery<TSchema> | UpdateWithAggregationPipeline;
|
|
173
|
+
} &
|
|
174
|
+
MongooseBulkUpdatePerOperationOptions;
|
|
175
|
+
|
|
176
|
+
export type DeleteOneModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
177
|
+
Omit<mongodb.DeleteOneModel<TSchema>, 'filter'> &
|
|
178
|
+
{ filter: QueryFilter<TSchema> };
|
|
179
|
+
|
|
180
|
+
export type DeleteManyModel<TSchema extends mongodb.Document = mongodb.Document> =
|
|
181
|
+
Omit<mongodb.DeleteManyModel<TSchema>, 'filter'> &
|
|
182
|
+
{ filter: QueryFilter<TSchema> };
|
|
183
|
+
|
|
184
|
+
export type AnyBulkWriteOperation<TSchema extends mongodb.Document = mongodb.Document> =
|
|
185
|
+
| { insertOne: InsertOneModel<TSchema> }
|
|
186
|
+
| { replaceOne: ReplaceOneModel<TSchema> }
|
|
187
|
+
| { updateOne: UpdateOneModel<TSchema> }
|
|
188
|
+
| { updateMany: UpdateManyModel<TSchema> }
|
|
189
|
+
| { deleteOne: DeleteOneModel<TSchema> }
|
|
190
|
+
| { deleteMany: DeleteManyModel<TSchema> };
|
|
191
|
+
|
|
130
192
|
const Model: Model<any>;
|
|
131
|
-
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
* Apply common casting logic to the given type, allowing:
|
|
196
|
+
* - strings for ObjectIds
|
|
197
|
+
* - strings and numbers for Dates
|
|
198
|
+
* - strings for Buffers
|
|
199
|
+
* - strings for UUIDs
|
|
200
|
+
* - POJOs for subdocuments
|
|
201
|
+
* - vanilla arrays of POJOs for document arrays
|
|
202
|
+
* - POJOs and array of arrays for maps
|
|
203
|
+
*/
|
|
204
|
+
type CreateObjectWithExtraKeys<T> = T | (T & Record<string, unknown>);
|
|
205
|
+
type ApplyBasicCreateCasting<T> = {
|
|
206
|
+
[K in keyof T]: NonNullable<T[K]> extends Map<infer KeyType extends string, infer ValueType>
|
|
207
|
+
? (Record<KeyType, ValueType> | Array<[KeyType, ValueType]> | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>)
|
|
208
|
+
: NonNullable<T[K]> extends Types.DocumentArray<infer RawSubdocType>
|
|
209
|
+
? RawSubdocType[] | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>
|
|
210
|
+
: NonNullable<T[K]> extends Document<any, any, infer RawSubdocType>
|
|
211
|
+
? CreateObjectWithExtraKeys<ApplyBasicCreateCasting<RawSubdocType>> | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>
|
|
212
|
+
: NonNullable<T[K]> extends TreatAsPrimitives
|
|
213
|
+
? QueryTypeCasting<T[K]>
|
|
214
|
+
: NonNullable<T[K]> extends object
|
|
215
|
+
? CreateObjectWithExtraKeys<ApplyBasicCreateCasting<T[K]>> | T[K] | QueryTypeCasting<Extract<T[K], TreatAsPrimitives>>
|
|
216
|
+
: QueryTypeCasting<T[K]>;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
type HasLeanOption<TSchema> = 'lean' extends keyof ObtainSchemaGeneric<TSchema, 'TSchemaOptions'> ?
|
|
220
|
+
ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>['lean'] extends Record<string, any> ?
|
|
221
|
+
true :
|
|
222
|
+
ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>['lean'] :
|
|
223
|
+
false;
|
|
224
|
+
|
|
225
|
+
/** True only if every member of the `defaultSort` union is set, so a union like `{ name: 1 } | undefined` is false */
|
|
226
|
+
type HasDefaultSortOption<TSchema> = ObtainSchemaGeneric<TSchema, 'TSchemaOptions'> extends { defaultSort: infer DefaultSort } ?
|
|
227
|
+
[Extract<DefaultSort, false | null | undefined | ''>] extends [never] ? true : false :
|
|
228
|
+
false;
|
|
229
|
+
|
|
230
|
+
/** `Model.findAndCount()` requires `sort` unless the schema sets `defaultSort`. */
|
|
231
|
+
type FindAndCountSortOption<TSchema> = HasDefaultSortOption<TSchema> extends true ? { sort?: any } : { sort: any };
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Models are fancy constructors compiled from `Schema` definitions.
|
|
235
|
+
* An instance of a model is called a document.
|
|
236
|
+
* Models are responsible for creating and reading documents from the underlying MongoDB database
|
|
237
|
+
*/
|
|
238
|
+
export interface Model<
|
|
239
|
+
TRawDocType,
|
|
240
|
+
TQueryHelpers = {},
|
|
241
|
+
TInstanceMethods = {},
|
|
242
|
+
TVirtuals = {},
|
|
243
|
+
THydratedDocumentType = HydratedDocument<TRawDocType, TVirtuals & TInstanceMethods, TQueryHelpers, TVirtuals>,
|
|
244
|
+
TSchema = any,
|
|
245
|
+
TLeanResultType = Default__v<Require_id<TRawDocType>>> extends
|
|
132
246
|
NodeJS.EventEmitter,
|
|
133
|
-
AcceptsDiscriminator,
|
|
134
247
|
IndexManager,
|
|
135
248
|
SessionStarter {
|
|
136
|
-
new <DocType =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
TVirtuals,
|
|
141
|
-
{},
|
|
142
|
-
ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
|
|
143
|
-
TVirtuals
|
|
144
|
-
>
|
|
145
|
-
> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
|
|
146
|
-
|
|
147
|
-
aggregate<R = any>(pipeline?: PipelineStage[], options?: AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
|
|
148
|
-
aggregate<R = any>(pipeline: PipelineStage[], callback?: Callback<R[]>): Aggregate<Array<R>>;
|
|
249
|
+
new <DocType = Partial<TRawDocType>>(doc?: DocType, fields?: any | null, options?: AnyObject): THydratedDocumentType;
|
|
250
|
+
|
|
251
|
+
aggregate<R = any>(pipeline?: PipelineStage[], options?: AggregateOptions): Aggregate<Array<R>>;
|
|
252
|
+
aggregate<R = any>(pipeline: PipelineStage[]): Aggregate<Array<R>>;
|
|
149
253
|
|
|
150
254
|
/** Base Mongoose instance the model uses. */
|
|
151
255
|
base: Mongoose;
|
|
152
256
|
|
|
257
|
+
/** Standard Schema adapter for validating input with this model's schema. */
|
|
258
|
+
readonly '~standard': StandardSchemaV1.Props<
|
|
259
|
+
Default__v<
|
|
260
|
+
Default_id<TRawDocType, ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>>,
|
|
261
|
+
ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>
|
|
262
|
+
>
|
|
263
|
+
>;
|
|
264
|
+
|
|
153
265
|
/**
|
|
154
266
|
* If this is a discriminator model, `baseModelName` is the name of
|
|
155
267
|
* the base model.
|
|
@@ -157,7 +269,19 @@ declare module 'mongoose' {
|
|
|
157
269
|
baseModelName: string | undefined;
|
|
158
270
|
|
|
159
271
|
/* Cast the given POJO to the model's schema */
|
|
160
|
-
castObject(obj: AnyObject, options?: { ignoreCastErrors?: boolean }):
|
|
272
|
+
castObject(obj: AnyObject, options?: { ignoreCastErrors?: boolean }): TRawDocType;
|
|
273
|
+
|
|
274
|
+
/* Apply defaults to the given document or POJO. */
|
|
275
|
+
applyDefaults(obj: AnyObject): AnyObject;
|
|
276
|
+
applyDefaults(obj: TRawDocType): TRawDocType;
|
|
277
|
+
|
|
278
|
+
/* Apply virtuals to the given POJO. */
|
|
279
|
+
applyVirtuals(obj: AnyObject, virtalsToApply?: string[]): AnyObject;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Apply this model's timestamps to a given POJO, including subdocument timestamps
|
|
283
|
+
*/
|
|
284
|
+
applyTimestamps(obj: AnyObject, options?: { isUpdate?: boolean, currentTime?: () => Date }): AnyObject;
|
|
161
285
|
|
|
162
286
|
/**
|
|
163
287
|
* Sends multiple `insertOne`, `updateOne`, `updateMany`, `replaceOne`,
|
|
@@ -166,12 +290,12 @@ declare module 'mongoose' {
|
|
|
166
290
|
* if you use `create()`) because with `bulkWrite()` there is only one network
|
|
167
291
|
* round trip to the MongoDB server.
|
|
168
292
|
*/
|
|
169
|
-
bulkWrite<DocContents =
|
|
170
|
-
writes: Array<
|
|
293
|
+
bulkWrite<DocContents = TRawDocType>(
|
|
294
|
+
writes: Array<AnyBulkWriteOperation<DocContents extends mongodb.Document ? DocContents : any>>,
|
|
171
295
|
options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions & { ordered: false }
|
|
172
296
|
): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[] } }>;
|
|
173
|
-
bulkWrite<DocContents =
|
|
174
|
-
writes: Array<
|
|
297
|
+
bulkWrite<DocContents = TRawDocType>(
|
|
298
|
+
writes: Array<AnyBulkWriteOperation<DocContents extends mongodb.Document ? DocContents : any>>,
|
|
175
299
|
options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions
|
|
176
300
|
): Promise<mongodb.BulkWriteResult>;
|
|
177
301
|
|
|
@@ -180,35 +304,62 @@ declare module 'mongoose' {
|
|
|
180
304
|
* sending multiple `save()` calls because with `bulkSave()` there is only one
|
|
181
305
|
* network round trip to the MongoDB server.
|
|
182
306
|
*/
|
|
183
|
-
bulkSave(documents: Array<
|
|
307
|
+
bulkSave(documents: Array<THydratedDocumentType>, options?: MongooseBulkSaveOptions): Promise<MongooseBulkWriteResult>;
|
|
184
308
|
|
|
185
309
|
/** Collection the model uses. */
|
|
186
310
|
collection: Collection;
|
|
187
311
|
|
|
188
|
-
/** Creates a `count` query: counts the number of documents that match `filter`. */
|
|
189
|
-
count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
190
|
-
count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
191
|
-
|
|
192
312
|
/** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
|
|
193
|
-
countDocuments(
|
|
194
|
-
|
|
313
|
+
countDocuments(
|
|
314
|
+
filter?: QueryFilter<TRawDocType>,
|
|
315
|
+
options?: (mongodb.CountOptions & MongooseBaseQueryOptions<TRawDocType> & mongodb.Abortable) | null
|
|
316
|
+
): QueryWithHelpers<
|
|
317
|
+
number,
|
|
318
|
+
THydratedDocumentType,
|
|
319
|
+
TQueryHelpers,
|
|
320
|
+
TRawDocType,
|
|
321
|
+
'countDocuments',
|
|
322
|
+
TInstanceMethods & TVirtuals
|
|
323
|
+
>;
|
|
324
|
+
countDocuments(
|
|
325
|
+
filter?: Query<any, any>,
|
|
326
|
+
options?: (mongodb.CountOptions & MongooseBaseQueryOptions<TRawDocType> & mongodb.Abortable) | null
|
|
327
|
+
): QueryWithHelpers<
|
|
328
|
+
number,
|
|
329
|
+
THydratedDocumentType,
|
|
330
|
+
TQueryHelpers,
|
|
331
|
+
TRawDocType,
|
|
332
|
+
'countDocuments',
|
|
333
|
+
TInstanceMethods & TVirtuals
|
|
334
|
+
>;
|
|
195
335
|
|
|
196
336
|
/** Creates a new document or documents */
|
|
197
|
-
create
|
|
198
|
-
create
|
|
199
|
-
create
|
|
200
|
-
create<
|
|
201
|
-
create
|
|
202
|
-
create
|
|
337
|
+
create(): Promise<null>;
|
|
338
|
+
create(doc: Partial<TRawDocType>): Promise<THydratedDocumentType>;
|
|
339
|
+
create(docs: Array<Partial<TRawDocType>>): Promise<THydratedDocumentType[]>;
|
|
340
|
+
create(docs: Array<DeepPartial<ApplyBasicCreateCasting<Require_id<TRawDocType>>>>, options: CreateOptions & { aggregateErrors: true }): Promise<(THydratedDocumentType | Error)[]>;
|
|
341
|
+
create(docs: Array<DeepPartial<ApplyBasicCreateCasting<Require_id<TRawDocType>>>>, options?: CreateOptions): Promise<THydratedDocumentType[]>;
|
|
342
|
+
create(doc: DeepPartial<ApplyBasicCreateCasting<Require_id<TRawDocType>>>): Promise<THydratedDocumentType>;
|
|
343
|
+
create(...docs: Array<DeepPartial<ApplyBasicCreateCasting<Require_id<TRawDocType>>>>): Promise<THydratedDocumentType[]>;
|
|
203
344
|
|
|
204
345
|
/**
|
|
205
346
|
* Create the collection for this model. By default, if no indexes are specified,
|
|
206
347
|
* mongoose will not create the collection for the model until any documents are
|
|
207
348
|
* created. Use this method to create the collection explicitly.
|
|
208
349
|
*/
|
|
209
|
-
createCollection<T extends mongodb.Document>(options
|
|
210
|
-
|
|
211
|
-
|
|
350
|
+
createCollection<T extends mongodb.Document>(options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'> & { middleware?: boolean | SkipMiddlewareOptions }): Promise<mongodb.Collection<T>>;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Create an [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/).
|
|
354
|
+
* This function only works when connected to MongoDB Atlas.
|
|
355
|
+
*/
|
|
356
|
+
createSearchIndex(description: SearchIndexDescription): Promise<string>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Creates all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) defined in this model's schema.
|
|
360
|
+
* This function only works when connected to MongoDB Atlas.
|
|
361
|
+
*/
|
|
362
|
+
createSearchIndexes(): Promise<string[]>;
|
|
212
363
|
|
|
213
364
|
/** Connection the model uses. */
|
|
214
365
|
db: Connection;
|
|
@@ -218,18 +369,84 @@ declare module 'mongoose' {
|
|
|
218
369
|
* Behaves like `remove()`, but deletes all documents that match `conditions`
|
|
219
370
|
* regardless of the `single` option.
|
|
220
371
|
*/
|
|
221
|
-
deleteMany(
|
|
222
|
-
|
|
223
|
-
|
|
372
|
+
deleteMany(
|
|
373
|
+
filter?: QueryFilter<TRawDocType>,
|
|
374
|
+
options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions<TRawDocType>) | null
|
|
375
|
+
): QueryWithHelpers<
|
|
376
|
+
mongodb.DeleteResult,
|
|
377
|
+
THydratedDocumentType,
|
|
378
|
+
TQueryHelpers,
|
|
379
|
+
TLeanResultType,
|
|
380
|
+
'deleteMany',
|
|
381
|
+
TInstanceMethods & TVirtuals
|
|
382
|
+
>;
|
|
383
|
+
deleteMany(
|
|
384
|
+
filter?: Query<any, any>,
|
|
385
|
+
options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions<TRawDocType>) | null
|
|
386
|
+
): QueryWithHelpers<
|
|
387
|
+
mongodb.DeleteResult,
|
|
388
|
+
THydratedDocumentType,
|
|
389
|
+
TQueryHelpers,
|
|
390
|
+
TLeanResultType,
|
|
391
|
+
'deleteMany',
|
|
392
|
+
TInstanceMethods & TVirtuals
|
|
393
|
+
>;
|
|
224
394
|
|
|
225
395
|
/**
|
|
226
396
|
* Deletes the first document that matches `conditions` from the collection.
|
|
227
397
|
* Behaves like `remove()`, but deletes at most one document regardless of the
|
|
228
398
|
* `single` option.
|
|
229
399
|
*/
|
|
230
|
-
deleteOne(
|
|
231
|
-
|
|
232
|
-
|
|
400
|
+
deleteOne(
|
|
401
|
+
filter?: QueryFilter<TRawDocType>,
|
|
402
|
+
options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions<TRawDocType>) | null
|
|
403
|
+
): QueryWithHelpers<
|
|
404
|
+
mongodb.DeleteResult,
|
|
405
|
+
THydratedDocumentType,
|
|
406
|
+
TQueryHelpers,
|
|
407
|
+
TLeanResultType,
|
|
408
|
+
'deleteOne',
|
|
409
|
+
TInstanceMethods & TVirtuals
|
|
410
|
+
>;
|
|
411
|
+
deleteOne(
|
|
412
|
+
filter?: Query<any, any>,
|
|
413
|
+
options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions<TRawDocType>) | null
|
|
414
|
+
): QueryWithHelpers<
|
|
415
|
+
mongodb.DeleteResult,
|
|
416
|
+
THydratedDocumentType,
|
|
417
|
+
TQueryHelpers,
|
|
418
|
+
TLeanResultType,
|
|
419
|
+
'deleteOne',
|
|
420
|
+
TInstanceMethods & TVirtuals
|
|
421
|
+
>;
|
|
422
|
+
|
|
423
|
+
/** Adds a discriminator type. */
|
|
424
|
+
discriminator<TDiscriminatorSchema extends Schema<any, any>>(
|
|
425
|
+
name: string | number,
|
|
426
|
+
schema: TDiscriminatorSchema,
|
|
427
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
428
|
+
): Model<
|
|
429
|
+
TRawDocType & InferSchemaType<TDiscriminatorSchema>,
|
|
430
|
+
TQueryHelpers & ObtainSchemaGeneric<TDiscriminatorSchema, 'TQueryHelpers'>,
|
|
431
|
+
TInstanceMethods & ObtainSchemaGeneric<TDiscriminatorSchema, 'TInstanceMethods'>,
|
|
432
|
+
TVirtuals & ObtainSchemaGeneric<TDiscriminatorSchema, 'TVirtuals'>
|
|
433
|
+
> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'> & ObtainSchemaGeneric<TDiscriminatorSchema, 'TStaticMethods'>;
|
|
434
|
+
discriminator<D>(
|
|
435
|
+
name: string | number,
|
|
436
|
+
schema: Schema,
|
|
437
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
438
|
+
): Model<D>;
|
|
439
|
+
discriminator<T, U>(
|
|
440
|
+
name: string | number,
|
|
441
|
+
schema: Schema<T, U>,
|
|
442
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
443
|
+
): U;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Delete an existing [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) by name.
|
|
447
|
+
* This function only works when connected to MongoDB Atlas.
|
|
448
|
+
*/
|
|
449
|
+
dropSearchIndex(name: string): Promise<void>;
|
|
233
450
|
|
|
234
451
|
/**
|
|
235
452
|
* Event emitter that reports any errors that occurred. Useful for global error
|
|
@@ -242,40 +459,183 @@ declare module 'mongoose' {
|
|
|
242
459
|
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
|
|
243
460
|
* `_id`, use `findById()` instead of `findOne()`.
|
|
244
461
|
*/
|
|
245
|
-
findById<
|
|
462
|
+
findById<const Projection extends ProjectionType<TRawDocType>>(
|
|
463
|
+
id: any,
|
|
464
|
+
projection: Projection,
|
|
465
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
466
|
+
): QueryWithHelpers<
|
|
467
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
468
|
+
THydratedDocumentType,
|
|
469
|
+
TQueryHelpers,
|
|
470
|
+
TLeanResultType,
|
|
471
|
+
'findOne',
|
|
472
|
+
TInstanceMethods & TVirtuals,
|
|
473
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
474
|
+
>;
|
|
475
|
+
findById<ResultDoc = THydratedDocumentType>(
|
|
246
476
|
id: any,
|
|
247
|
-
projection
|
|
248
|
-
options
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
477
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
478
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
479
|
+
): QueryWithHelpers<
|
|
480
|
+
TLeanResultType | null,
|
|
481
|
+
ResultDoc,
|
|
482
|
+
TQueryHelpers,
|
|
483
|
+
TLeanResultType,
|
|
484
|
+
'findOne',
|
|
485
|
+
TInstanceMethods & TVirtuals
|
|
486
|
+
>;
|
|
487
|
+
findById<ResultDoc = THydratedDocumentType>(
|
|
252
488
|
id: any,
|
|
253
|
-
projection
|
|
254
|
-
|
|
255
|
-
): QueryWithHelpers<
|
|
489
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
490
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
491
|
+
): QueryWithHelpers<
|
|
492
|
+
ResultDoc | null,
|
|
493
|
+
ResultDoc,
|
|
494
|
+
TQueryHelpers,
|
|
495
|
+
TLeanResultType,
|
|
496
|
+
'findOne',
|
|
497
|
+
TInstanceMethods & TVirtuals
|
|
498
|
+
>;
|
|
499
|
+
findById<ResultDoc = THydratedDocumentType>(
|
|
500
|
+
id?: any,
|
|
501
|
+
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
502
|
+
options?: QueryOptions<TRawDocType> | null
|
|
503
|
+
): QueryWithHelpers<
|
|
504
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
505
|
+
ResultDoc,
|
|
506
|
+
TQueryHelpers,
|
|
507
|
+
TLeanResultType,
|
|
508
|
+
'findOne',
|
|
509
|
+
TInstanceMethods & TVirtuals
|
|
510
|
+
>;
|
|
256
511
|
|
|
257
512
|
/** Finds one document. */
|
|
258
|
-
findOne<
|
|
259
|
-
filter
|
|
260
|
-
projection
|
|
261
|
-
options?: QueryOptions<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
513
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
514
|
+
filter: QueryFilter<TRawDocType>,
|
|
515
|
+
projection: Projection,
|
|
516
|
+
options?: QueryOptions<TRawDocType> & { lean?: false } & mongodb.Abortable
|
|
517
|
+
): QueryWithHelpers<
|
|
518
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
519
|
+
THydratedDocumentType,
|
|
520
|
+
TQueryHelpers,
|
|
521
|
+
TLeanResultType,
|
|
522
|
+
'findOne',
|
|
523
|
+
TInstanceMethods & TVirtuals,
|
|
524
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
525
|
+
>;
|
|
526
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
527
|
+
filter: QueryFilter<TRawDocType>,
|
|
528
|
+
projection: undefined | null,
|
|
529
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false } & mongodb.Abortable
|
|
530
|
+
): QueryWithHelpers<
|
|
531
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
532
|
+
THydratedDocumentType,
|
|
533
|
+
TQueryHelpers,
|
|
534
|
+
TLeanResultType,
|
|
535
|
+
'findOne',
|
|
536
|
+
TInstanceMethods & TVirtuals,
|
|
537
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
538
|
+
>;
|
|
539
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
540
|
+
filter: QueryFilter<TRawDocType>,
|
|
541
|
+
projection: Projection,
|
|
542
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
543
|
+
): QueryWithHelpers<
|
|
544
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
545
|
+
THydratedDocumentType,
|
|
546
|
+
TQueryHelpers,
|
|
547
|
+
TLeanResultType,
|
|
548
|
+
'findOne',
|
|
549
|
+
TInstanceMethods & TVirtuals,
|
|
550
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
551
|
+
>;
|
|
552
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
553
|
+
filter: QueryFilter<TRawDocType>,
|
|
554
|
+
projection: undefined | null,
|
|
555
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true } & mongodb.Abortable
|
|
556
|
+
): QueryWithHelpers<
|
|
557
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
558
|
+
THydratedDocumentType,
|
|
559
|
+
TQueryHelpers,
|
|
560
|
+
TLeanResultType,
|
|
561
|
+
'findOne',
|
|
562
|
+
TInstanceMethods & TVirtuals,
|
|
563
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
564
|
+
>;
|
|
565
|
+
findOne<ResultDoc = THydratedDocumentType>(
|
|
566
|
+
filter: QueryFilter<TRawDocType>,
|
|
567
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
568
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
569
|
+
): QueryWithHelpers<
|
|
570
|
+
TLeanResultType | null,
|
|
571
|
+
ResultDoc,
|
|
572
|
+
TQueryHelpers,
|
|
573
|
+
TLeanResultType,
|
|
574
|
+
'findOne',
|
|
575
|
+
TInstanceMethods & TVirtuals
|
|
576
|
+
>;
|
|
577
|
+
findOne(
|
|
578
|
+
filter: Query<any, any>,
|
|
579
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
580
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
581
|
+
): QueryWithHelpers<
|
|
582
|
+
TLeanResultType | null,
|
|
583
|
+
THydratedDocumentType,
|
|
584
|
+
TQueryHelpers,
|
|
585
|
+
TLeanResultType,
|
|
586
|
+
'findOne',
|
|
587
|
+
TInstanceMethods & TVirtuals
|
|
588
|
+
>;
|
|
589
|
+
findOne<ResultDoc = THydratedDocumentType>(
|
|
590
|
+
filter: QueryFilter<TRawDocType>,
|
|
591
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
592
|
+
options: QueryOptions<TRawDocType> & { lean: false } & mongodb.Abortable
|
|
593
|
+
): QueryWithHelpers<
|
|
594
|
+
ResultDoc | null,
|
|
595
|
+
ResultDoc,
|
|
596
|
+
TQueryHelpers,
|
|
597
|
+
TLeanResultType,
|
|
598
|
+
'findOne',
|
|
599
|
+
TInstanceMethods & TVirtuals
|
|
600
|
+
>;
|
|
601
|
+
findOne<ResultDoc = THydratedDocumentType>(
|
|
602
|
+
filter?: QueryFilter<TRawDocType>,
|
|
603
|
+
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
604
|
+
options?: QueryOptions<TRawDocType> & mongodb.Abortable | null | undefined
|
|
605
|
+
): QueryWithHelpers<
|
|
606
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
607
|
+
ResultDoc,
|
|
608
|
+
TQueryHelpers,
|
|
609
|
+
TLeanResultType,
|
|
610
|
+
'findOne',
|
|
611
|
+
TInstanceMethods & TVirtuals
|
|
612
|
+
>;
|
|
613
|
+
findOne(
|
|
614
|
+
filter?: Query<any, any>,
|
|
615
|
+
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
616
|
+
options?: QueryOptions<TRawDocType> & mongodb.Abortable | null | undefined
|
|
617
|
+
): QueryWithHelpers<
|
|
618
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : THydratedDocumentType | null,
|
|
619
|
+
THydratedDocumentType,
|
|
620
|
+
TQueryHelpers,
|
|
621
|
+
TLeanResultType,
|
|
622
|
+
'findOne',
|
|
623
|
+
TInstanceMethods & TVirtuals
|
|
624
|
+
>;
|
|
273
625
|
|
|
274
626
|
/**
|
|
275
627
|
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
|
|
276
628
|
* The document returned has no paths marked as modified initially.
|
|
629
|
+
* With `strict: false`, fields not in the schema are kept on the document; pass
|
|
630
|
+
* `ExtraFields` to describe their types, e.g.
|
|
631
|
+
* `Model.hydrate<{ totalOrders: number }>(obj, null, { strict: false })`.
|
|
277
632
|
*/
|
|
278
|
-
hydrate
|
|
633
|
+
hydrate<ExtraFields = unknown>(
|
|
634
|
+
obj: any,
|
|
635
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
636
|
+
options: HydrateOptions & { strict: false }
|
|
637
|
+
): THydratedDocumentType & ExtraFields;
|
|
638
|
+
hydrate(obj: any, projection?: ProjectionType<TRawDocType> | null | undefined, options?: HydrateOptions): THydratedDocumentType;
|
|
279
639
|
|
|
280
640
|
/**
|
|
281
641
|
* This function is responsible for building [indexes](https://www.mongodb.com/docs/manual/indexes/),
|
|
@@ -285,33 +645,99 @@ declare module 'mongoose' {
|
|
|
285
645
|
* [`connection.model()`](/docs/api/connection.html#connection_Connection-model), so you
|
|
286
646
|
* don't need to call it.
|
|
287
647
|
*/
|
|
288
|
-
init(
|
|
648
|
+
init(): Promise<THydratedDocumentType>;
|
|
289
649
|
|
|
290
650
|
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
|
|
291
|
-
insertMany
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
insertMany
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
651
|
+
insertMany(
|
|
652
|
+
docs: Array<TRawDocType>
|
|
653
|
+
): Promise<Array<THydratedDocumentType>>;
|
|
654
|
+
insertMany(
|
|
655
|
+
doc: Array<TRawDocType>,
|
|
656
|
+
options: InsertManyOptions & { ordered: false; rawResult: true; }
|
|
657
|
+
): Promise<mongodb.InsertManyResult<Require_id<TRawDocType>> & {
|
|
658
|
+
mongoose: {
|
|
659
|
+
validationErrors: (CastError | Error.ValidatorError)[];
|
|
660
|
+
results: Array<
|
|
661
|
+
Error |
|
|
662
|
+
Object |
|
|
663
|
+
THydratedDocumentType
|
|
664
|
+
>
|
|
665
|
+
}
|
|
666
|
+
}>;
|
|
667
|
+
insertMany(
|
|
668
|
+
docs: Array<TRawDocType>,
|
|
669
|
+
options: InsertManyOptions & { lean: true, rawResult: true; }
|
|
670
|
+
): Promise<mongodb.InsertManyResult<Require_id<TRawDocType>>>;
|
|
671
|
+
insertMany<DocContents = TRawDocType>(
|
|
672
|
+
doc: DocContents | TRawDocType,
|
|
302
673
|
options: InsertManyOptions & { ordered: false; rawResult: true; }
|
|
303
|
-
): Promise<mongodb.InsertManyResult<
|
|
674
|
+
): Promise<mongodb.InsertManyResult<Require_id<DocContents>> & {
|
|
304
675
|
mongoose: {
|
|
305
|
-
validationErrors: Error[];
|
|
306
|
-
results: Array<
|
|
676
|
+
validationErrors: (CastError | Error.ValidatorError)[];
|
|
677
|
+
results: Array<
|
|
678
|
+
Error |
|
|
679
|
+
Object |
|
|
680
|
+
MergeType<THydratedDocumentType, DocContents>
|
|
681
|
+
>
|
|
307
682
|
}
|
|
308
683
|
}>;
|
|
309
|
-
insertMany
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
insertMany
|
|
314
|
-
|
|
684
|
+
insertMany(
|
|
685
|
+
docs: Array<TRawDocType>,
|
|
686
|
+
options: InsertManyOptions & { lean: true; }
|
|
687
|
+
): Promise<Array<Require_id<TRawDocType>>>;
|
|
688
|
+
insertMany(
|
|
689
|
+
docs: Array<TRawDocType>,
|
|
690
|
+
options: InsertManyOptions & { rawResult: true; }
|
|
691
|
+
): Promise<mongodb.InsertManyResult<Require_id<THydratedDocumentType>>>;
|
|
692
|
+
insertMany<DocContents = TRawDocType>(
|
|
693
|
+
docs: Array<DocContents | TRawDocType>,
|
|
694
|
+
options: InsertManyOptions & { lean: true; }
|
|
695
|
+
): Promise<Array<Require_id<DocContents>>>;
|
|
696
|
+
insertMany<DocContents = TRawDocType>(
|
|
697
|
+
docs: Array<DocContents | TRawDocType>,
|
|
698
|
+
options: InsertManyOptions & { rawResult: true; }
|
|
699
|
+
): Promise<mongodb.InsertManyResult<Require_id<DocContents>>>;
|
|
700
|
+
insertMany<DocContents = TRawDocType>(
|
|
701
|
+
doc: DocContents,
|
|
702
|
+
options: InsertManyOptions & { lean: true; }
|
|
703
|
+
): Promise<Array<Require_id<DocContents>>>;
|
|
704
|
+
insertMany<DocContents = TRawDocType>(
|
|
705
|
+
doc: DocContents,
|
|
706
|
+
options: InsertManyOptions & { rawResult: true; }
|
|
707
|
+
): Promise<mongodb.InsertManyResult<Require_id<DocContents>>>;
|
|
708
|
+
insertMany(
|
|
709
|
+
doc: Array<TRawDocType>,
|
|
710
|
+
options: InsertManyOptions
|
|
711
|
+
): Promise<Array<THydratedDocumentType>>;
|
|
712
|
+
insertMany<DocContents = TRawDocType>(
|
|
713
|
+
docs: Array<DocContents | TRawDocType>
|
|
714
|
+
): Promise<Array<MergeType<THydratedDocumentType, Omit<DocContents, '_id'>>>>;
|
|
715
|
+
insertMany<DocContents = TRawDocType>(
|
|
716
|
+
doc: DocContents,
|
|
717
|
+
options: InsertManyOptions
|
|
718
|
+
): Promise<Array<MergeType<THydratedDocumentType, Omit<DocContents, '_id'>>>>;
|
|
719
|
+
insertMany<DocContents = TRawDocType>(
|
|
720
|
+
docs: Array<DocContents | TRawDocType>,
|
|
721
|
+
options: InsertManyOptions
|
|
722
|
+
): Promise<Array<MergeType<THydratedDocumentType, Omit<DocContents, '_id'>>>>;
|
|
723
|
+
insertMany<DocContents = TRawDocType>(
|
|
724
|
+
doc: DocContents
|
|
725
|
+
): Promise<
|
|
726
|
+
Array<MergeType<THydratedDocumentType, Omit<DocContents, '_id'>>>
|
|
727
|
+
>;
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Shortcut for saving one document to the database.
|
|
731
|
+
* `MyModel.insertOne(obj, options)` is almost equivalent to `new MyModel(obj).save(options)`.
|
|
732
|
+
* The difference is that `insertOne()` checks if `obj` is already a document, and checks for discriminators.
|
|
733
|
+
*/
|
|
734
|
+
insertOne(doc: Partial<ApplyBasicCreateCasting<TRawDocType>>, options?: SaveOptions): Promise<THydratedDocumentType>;
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
|
|
738
|
+
* This function only works when connected to MongoDB Atlas.
|
|
739
|
+
*/
|
|
740
|
+
listSearchIndexes(options?: mongodb.ListSearchIndexesOptions): Promise<Array<SearchIndexInfo>>;
|
|
315
741
|
|
|
316
742
|
/** The name of the model */
|
|
317
743
|
modelName: string;
|
|
@@ -320,30 +746,42 @@ declare module 'mongoose' {
|
|
|
320
746
|
populate(
|
|
321
747
|
docs: Array<any>,
|
|
322
748
|
options: PopulateOptions | Array<PopulateOptions> | string
|
|
323
|
-
): Promise<Array<
|
|
749
|
+
): Promise<Array<THydratedDocumentType>>;
|
|
324
750
|
populate(
|
|
325
|
-
doc: any,
|
|
326
|
-
|
|
327
|
-
): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
751
|
+
doc: any, options: PopulateOptions | Array<PopulateOptions> | string
|
|
752
|
+
): Promise<THydratedDocumentType>;
|
|
328
753
|
populate<Paths>(
|
|
329
754
|
docs: Array<any>,
|
|
330
755
|
options: PopulateOptions | Array<PopulateOptions> | string
|
|
331
|
-
): Promise<
|
|
756
|
+
): Promise<Array<PopulateDocumentResult<THydratedDocumentType, Paths, PopulatedPathsDocumentType<TRawDocType, Paths>, TRawDocType>>>;
|
|
332
757
|
populate<Paths>(
|
|
333
|
-
doc:
|
|
334
|
-
|
|
335
|
-
|
|
758
|
+
doc: any, options: PopulateOptions | Array<PopulateOptions> | string
|
|
759
|
+
): Promise<PopulateDocumentResult<THydratedDocumentType, Paths, PopulatedPathsDocumentType<TRawDocType, Paths>, TRawDocType>>;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Update an existing [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/).
|
|
763
|
+
* This function only works when connected to MongoDB Atlas.
|
|
764
|
+
*/
|
|
765
|
+
updateSearchIndex(name: string, definition: AnyObject): Promise<void>;
|
|
336
766
|
|
|
337
|
-
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
767
|
+
/**
|
|
768
|
+
* Changes the Connection instance this model uses to make requests to MongoDB.
|
|
769
|
+
* This function is most useful for changing the Connection that a Model defined using `mongoose.model()` uses
|
|
770
|
+
* after initialization.
|
|
771
|
+
*/
|
|
772
|
+
useConnection(connection: Connection): this;
|
|
773
|
+
|
|
774
|
+
/** Casts and validates the given object against this model's schema, returning the casted-and-validated copy of `obj`, passing the given `context` to custom validators. */
|
|
775
|
+
validate(): Promise<TRawDocType>;
|
|
776
|
+
validate(obj: any): Promise<TRawDocType>;
|
|
777
|
+
validate(obj: any, pathsOrOptions: PathsToValidate): Promise<TRawDocType>;
|
|
778
|
+
validate(obj: any, pathsOrOptions: { pathsToSkip?: pathsToSkip }): Promise<TRawDocType>;
|
|
341
779
|
|
|
342
780
|
/** Watches the underlying collection for changes using [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/). */
|
|
343
|
-
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType>;
|
|
781
|
+
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>;
|
|
344
782
|
|
|
345
783
|
/** Adds a `$where` clause to this query */
|
|
346
|
-
$where(argument: string | Function): QueryWithHelpers<Array<
|
|
784
|
+
$where(argument: string | Function): QueryWithHelpers<Array<THydratedDocumentType>, THydratedDocumentType, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>;
|
|
347
785
|
|
|
348
786
|
/** Registered discriminators for this model. */
|
|
349
787
|
discriminators: { [name: string]: Model<any> } | undefined;
|
|
@@ -352,137 +790,986 @@ declare module 'mongoose' {
|
|
|
352
790
|
translateAliases(raw: any): any;
|
|
353
791
|
|
|
354
792
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
355
|
-
distinct<
|
|
793
|
+
distinct<DocKey extends string>(
|
|
794
|
+
field: DocKey,
|
|
795
|
+
filter?: QueryFilter<TRawDocType>,
|
|
796
|
+
options?: QueryOptions<TRawDocType>
|
|
797
|
+
): QueryWithHelpers<
|
|
798
|
+
Array<
|
|
799
|
+
DocKey extends keyof WithLevel1NestedPaths<TRawDocType>
|
|
800
|
+
? WithoutUndefined<Unpacked<WithLevel1NestedPaths<TRawDocType>[DocKey]>>
|
|
801
|
+
: unknown
|
|
802
|
+
>,
|
|
803
|
+
THydratedDocumentType,
|
|
804
|
+
TQueryHelpers,
|
|
805
|
+
TLeanResultType,
|
|
806
|
+
'distinct',
|
|
807
|
+
TInstanceMethods & TVirtuals
|
|
808
|
+
>;
|
|
809
|
+
distinct<DocKey extends string>(
|
|
810
|
+
field: DocKey,
|
|
811
|
+
filter?: Query<any, any>,
|
|
812
|
+
options?: QueryOptions<TRawDocType>
|
|
813
|
+
): QueryWithHelpers<
|
|
814
|
+
Array<
|
|
815
|
+
DocKey extends keyof WithLevel1NestedPaths<TRawDocType>
|
|
816
|
+
? WithoutUndefined<Unpacked<WithLevel1NestedPaths<TRawDocType>[DocKey]>>
|
|
817
|
+
: unknown
|
|
818
|
+
>,
|
|
819
|
+
THydratedDocumentType,
|
|
820
|
+
TQueryHelpers,
|
|
821
|
+
TLeanResultType,
|
|
822
|
+
'distinct',
|
|
823
|
+
TInstanceMethods & TVirtuals
|
|
824
|
+
>;
|
|
356
825
|
|
|
357
826
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
358
|
-
estimatedDocumentCount(options?: QueryOptions<
|
|
827
|
+
estimatedDocumentCount(options?: QueryOptions<TRawDocType>): QueryWithHelpers<
|
|
828
|
+
number,
|
|
829
|
+
THydratedDocumentType,
|
|
830
|
+
TQueryHelpers,
|
|
831
|
+
TLeanResultType,
|
|
832
|
+
'estimatedDocumentCount',
|
|
833
|
+
TInstanceMethods & TVirtuals
|
|
834
|
+
>;
|
|
359
835
|
|
|
360
836
|
/**
|
|
361
837
|
* Returns a document with its `_id` if at least one document exists in the database that matches
|
|
362
838
|
* the given `filter`, and `null` otherwise.
|
|
363
839
|
*/
|
|
364
|
-
exists(
|
|
365
|
-
|
|
840
|
+
exists(
|
|
841
|
+
filter: QueryFilter<TRawDocType>
|
|
842
|
+
): QueryWithHelpers<
|
|
843
|
+
{ _id: InferId<TRawDocType> } | null,
|
|
844
|
+
THydratedDocumentType,
|
|
845
|
+
TQueryHelpers,
|
|
846
|
+
TLeanResultType,
|
|
847
|
+
'findOne',
|
|
848
|
+
TInstanceMethods & TVirtuals
|
|
849
|
+
>;
|
|
850
|
+
exists(
|
|
851
|
+
filter: Query<any, any>
|
|
852
|
+
): QueryWithHelpers<
|
|
853
|
+
{ _id: InferId<TRawDocType> } | null,
|
|
854
|
+
THydratedDocumentType,
|
|
855
|
+
TQueryHelpers,
|
|
856
|
+
TLeanResultType,
|
|
857
|
+
'findOne',
|
|
858
|
+
TInstanceMethods & TVirtuals
|
|
859
|
+
>;
|
|
366
860
|
|
|
367
861
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
368
|
-
find<
|
|
369
|
-
filter:
|
|
370
|
-
projection
|
|
371
|
-
options?: QueryOptions<
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
): QueryWithHelpers<
|
|
862
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
863
|
+
filter: QueryFilter<TRawDocType>,
|
|
864
|
+
projection: Projection,
|
|
865
|
+
options?: QueryOptions<TRawDocType> & { lean?: false } & mongodb.Abortable
|
|
866
|
+
): QueryWithHelpers<
|
|
867
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>[],
|
|
868
|
+
THydratedDocumentType,
|
|
869
|
+
TQueryHelpers,
|
|
870
|
+
TLeanResultType,
|
|
871
|
+
'find',
|
|
872
|
+
TInstanceMethods & TVirtuals,
|
|
873
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
874
|
+
>;
|
|
875
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
876
|
+
filter: QueryFilter<TRawDocType>,
|
|
877
|
+
projection: undefined | null,
|
|
878
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false } & mongodb.Abortable
|
|
879
|
+
): QueryWithHelpers<
|
|
880
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>[],
|
|
881
|
+
THydratedDocumentType,
|
|
882
|
+
TQueryHelpers,
|
|
883
|
+
TLeanResultType,
|
|
884
|
+
'find',
|
|
885
|
+
TInstanceMethods & TVirtuals,
|
|
886
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
887
|
+
>;
|
|
888
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
889
|
+
filter: QueryFilter<TRawDocType>,
|
|
890
|
+
projection: Projection,
|
|
891
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
892
|
+
): QueryWithHelpers<
|
|
893
|
+
ApplyProjection<TRawDocType, Projection>[],
|
|
894
|
+
THydratedDocumentType,
|
|
895
|
+
TQueryHelpers,
|
|
896
|
+
TLeanResultType,
|
|
897
|
+
'find',
|
|
898
|
+
TInstanceMethods & TVirtuals,
|
|
899
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
900
|
+
>;
|
|
901
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
902
|
+
filter: QueryFilter<TRawDocType>,
|
|
903
|
+
projection: undefined | null,
|
|
904
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true } & mongodb.Abortable
|
|
905
|
+
): QueryWithHelpers<
|
|
906
|
+
ApplyProjection<TRawDocType, Projection>[],
|
|
907
|
+
THydratedDocumentType,
|
|
908
|
+
TQueryHelpers,
|
|
909
|
+
TLeanResultType,
|
|
910
|
+
'find',
|
|
911
|
+
TInstanceMethods & TVirtuals,
|
|
912
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
913
|
+
>;
|
|
914
|
+
find<ResultDoc = THydratedDocumentType>(
|
|
915
|
+
filter: QueryFilter<TRawDocType>,
|
|
916
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
917
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
918
|
+
): QueryWithHelpers<
|
|
919
|
+
GetLeanResultType<TLeanResultType, TRawDocType[], 'find'>,
|
|
920
|
+
ResultDoc,
|
|
921
|
+
TQueryHelpers,
|
|
922
|
+
TLeanResultType,
|
|
923
|
+
'find',
|
|
924
|
+
TInstanceMethods & TVirtuals
|
|
925
|
+
>;
|
|
926
|
+
find(
|
|
927
|
+
filter: Query<any, any>,
|
|
928
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
929
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
930
|
+
): QueryWithHelpers<
|
|
931
|
+
GetLeanResultType<TLeanResultType, TRawDocType[], 'find'>,
|
|
932
|
+
THydratedDocumentType,
|
|
933
|
+
TQueryHelpers,
|
|
934
|
+
TLeanResultType,
|
|
935
|
+
'find',
|
|
936
|
+
TInstanceMethods & TVirtuals
|
|
937
|
+
>;
|
|
938
|
+
find<ResultDoc = THydratedDocumentType>(
|
|
939
|
+
filter: QueryFilter<TRawDocType>,
|
|
940
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
941
|
+
options: QueryOptions<TRawDocType> & { lean: false } & mongodb.Abortable
|
|
942
|
+
): QueryWithHelpers<
|
|
943
|
+
ResultDoc[],
|
|
944
|
+
ResultDoc,
|
|
945
|
+
TQueryHelpers,
|
|
946
|
+
TLeanResultType,
|
|
947
|
+
'find',
|
|
948
|
+
TInstanceMethods & TVirtuals
|
|
949
|
+
>;
|
|
950
|
+
find<ResultDoc = THydratedDocumentType>(
|
|
951
|
+
filter?: QueryFilter<TRawDocType>,
|
|
952
|
+
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
953
|
+
options?: QueryOptions<TRawDocType> & mongodb.Abortable
|
|
954
|
+
): QueryWithHelpers<
|
|
955
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType[] : ResultDoc[],
|
|
956
|
+
ResultDoc,
|
|
957
|
+
TQueryHelpers,
|
|
958
|
+
TLeanResultType,
|
|
959
|
+
'find',
|
|
960
|
+
TInstanceMethods & TVirtuals
|
|
961
|
+
>;
|
|
962
|
+
find(
|
|
963
|
+
filter?: Query<any, any>,
|
|
964
|
+
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
965
|
+
options?: QueryOptions<TRawDocType> & mongodb.Abortable
|
|
966
|
+
): QueryWithHelpers<
|
|
967
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType[] : THydratedDocumentType[],
|
|
968
|
+
THydratedDocumentType,
|
|
969
|
+
TQueryHelpers,
|
|
970
|
+
TLeanResultType,
|
|
971
|
+
'find',
|
|
972
|
+
TInstanceMethods & TVirtuals
|
|
973
|
+
>;
|
|
974
|
+
|
|
975
|
+
/** Finds documents and counts the number of documents matching `filter`. */
|
|
976
|
+
findAndCount<const Projection extends ProjectionType<TRawDocType>>(
|
|
977
|
+
filter: QueryFilter<TRawDocType>,
|
|
978
|
+
projection: Projection,
|
|
979
|
+
options: QueryOptions<TRawDocType> & FindAndCountSortOption<TSchema> & { limit: number; lean: true } & mongodb.Abortable
|
|
980
|
+
): Promise<[ApplyProjection<TRawDocType, Projection>[], number]>;
|
|
981
|
+
findAndCount<ResultDoc = THydratedDocumentType>(
|
|
982
|
+
filter: QueryFilter<TRawDocType>,
|
|
983
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
984
|
+
options: QueryOptions<TRawDocType> & FindAndCountSortOption<TSchema> & { limit: number; lean: true } & mongodb.Abortable
|
|
985
|
+
): Promise<[GetLeanResultType<TLeanResultType, TRawDocType[], 'find'>, number]>;
|
|
986
|
+
findAndCount<ResultDoc = THydratedDocumentType>(
|
|
987
|
+
filter: QueryFilter<TRawDocType>,
|
|
988
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
989
|
+
options: QueryOptions<TRawDocType> & FindAndCountSortOption<TSchema> & { limit: number; lean: false } & mongodb.Abortable
|
|
990
|
+
): Promise<[ResultDoc[], number]>;
|
|
991
|
+
findAndCount<ResultDoc = THydratedDocumentType>(
|
|
992
|
+
filter: QueryFilter<TRawDocType>,
|
|
993
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
994
|
+
options: QueryOptions<TRawDocType> & FindAndCountSortOption<TSchema> & { limit: number } & mongodb.Abortable
|
|
995
|
+
): Promise<[HasLeanOption<TSchema> extends true ? TLeanResultType[] : ResultDoc[], number]>;
|
|
386
996
|
|
|
387
997
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
388
|
-
findByIdAndDelete<
|
|
998
|
+
findByIdAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
999
|
+
id: mongodb.ObjectId | any,
|
|
1000
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1001
|
+
): QueryWithHelpers<
|
|
1002
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1003
|
+
THydratedDocumentType,
|
|
1004
|
+
TQueryHelpers,
|
|
1005
|
+
TLeanResultType,
|
|
1006
|
+
'findOneAndDelete',
|
|
1007
|
+
TInstanceMethods & TVirtuals,
|
|
1008
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1009
|
+
>;
|
|
1010
|
+
findByIdAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1011
|
+
id: mongodb.ObjectId | any,
|
|
1012
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1013
|
+
): QueryWithHelpers<
|
|
1014
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1015
|
+
THydratedDocumentType,
|
|
1016
|
+
TQueryHelpers,
|
|
1017
|
+
TLeanResultType,
|
|
1018
|
+
'findOneAndDelete',
|
|
1019
|
+
TInstanceMethods & TVirtuals,
|
|
1020
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1021
|
+
>;
|
|
1022
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1023
|
+
id: mongodb.ObjectId | any,
|
|
1024
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
|
|
1025
|
+
): QueryWithHelpers<
|
|
1026
|
+
ModifyResult<TLeanResultType>,
|
|
1027
|
+
ResultDoc,
|
|
1028
|
+
TQueryHelpers,
|
|
1029
|
+
TLeanResultType,
|
|
1030
|
+
'findOneAndDelete',
|
|
1031
|
+
TInstanceMethods & TVirtuals
|
|
1032
|
+
>;
|
|
1033
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1034
|
+
id: mongodb.ObjectId | any,
|
|
1035
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1036
|
+
): QueryWithHelpers<
|
|
1037
|
+
TLeanResultType | null,
|
|
1038
|
+
ResultDoc,
|
|
1039
|
+
TQueryHelpers,
|
|
1040
|
+
TLeanResultType,
|
|
1041
|
+
'findOneAndDelete',
|
|
1042
|
+
TInstanceMethods & TVirtuals
|
|
1043
|
+
>;
|
|
1044
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1045
|
+
id: mongodb.ObjectId | any,
|
|
1046
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1047
|
+
): QueryWithHelpers<
|
|
1048
|
+
ResultDoc | null,
|
|
1049
|
+
ResultDoc,
|
|
1050
|
+
TQueryHelpers,
|
|
1051
|
+
TLeanResultType,
|
|
1052
|
+
'findOneAndDelete',
|
|
1053
|
+
TInstanceMethods & TVirtuals
|
|
1054
|
+
>;
|
|
1055
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1056
|
+
id: mongodb.ObjectId | any,
|
|
1057
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1058
|
+
): QueryWithHelpers<
|
|
1059
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TLeanResultType> : ModifyResult<ResultDoc>,
|
|
1060
|
+
ResultDoc,
|
|
1061
|
+
TQueryHelpers,
|
|
1062
|
+
TLeanResultType,
|
|
1063
|
+
'findOneAndDelete',
|
|
1064
|
+
TInstanceMethods & TVirtuals
|
|
1065
|
+
>;
|
|
1066
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1067
|
+
id?: mongodb.ObjectId | any,
|
|
1068
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1069
|
+
): QueryWithHelpers<
|
|
1070
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
1071
|
+
ResultDoc,
|
|
1072
|
+
TQueryHelpers,
|
|
1073
|
+
TLeanResultType,
|
|
1074
|
+
'findOneAndDelete',
|
|
1075
|
+
TInstanceMethods & TVirtuals
|
|
1076
|
+
>;
|
|
389
1077
|
|
|
390
|
-
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
|
|
391
|
-
findByIdAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
392
1078
|
|
|
393
1079
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
394
|
-
findByIdAndUpdate<
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
1080
|
+
findByIdAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1081
|
+
id: mongodb.ObjectId | any,
|
|
1082
|
+
update: UpdateQuery<TRawDocType>,
|
|
1083
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1084
|
+
): QueryWithHelpers<
|
|
1085
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1086
|
+
THydratedDocumentType,
|
|
1087
|
+
TQueryHelpers,
|
|
1088
|
+
TLeanResultType,
|
|
1089
|
+
'findOneAndUpdate',
|
|
1090
|
+
TInstanceMethods & TVirtuals,
|
|
1091
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1092
|
+
>;
|
|
1093
|
+
findByIdAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1094
|
+
id: mongodb.ObjectId | any,
|
|
1095
|
+
update: UpdateQuery<TRawDocType>,
|
|
1096
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1097
|
+
): QueryWithHelpers<
|
|
1098
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1099
|
+
THydratedDocumentType,
|
|
1100
|
+
TQueryHelpers,
|
|
1101
|
+
TLeanResultType,
|
|
1102
|
+
'findOneAndUpdate',
|
|
1103
|
+
TInstanceMethods & TVirtuals,
|
|
1104
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1105
|
+
>;
|
|
1106
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1107
|
+
filter: QueryFilter<TRawDocType>,
|
|
1108
|
+
update: UpdateQuery<TRawDocType>,
|
|
1109
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
|
|
1110
|
+
): QueryWithHelpers<
|
|
1111
|
+
ModifyResult<TRawDocType>,
|
|
1112
|
+
ResultDoc,
|
|
1113
|
+
TQueryHelpers,
|
|
1114
|
+
TLeanResultType,
|
|
1115
|
+
'findOneAndUpdate',
|
|
1116
|
+
TInstanceMethods & TVirtuals
|
|
1117
|
+
>;
|
|
1118
|
+
findByIdAndUpdate(
|
|
1119
|
+
filter: Query<any, any>,
|
|
1120
|
+
update: UpdateQuery<TRawDocType>,
|
|
1121
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
|
|
1122
|
+
): QueryWithHelpers<
|
|
1123
|
+
ModifyResult<TRawDocType>,
|
|
1124
|
+
THydratedDocumentType,
|
|
1125
|
+
TQueryHelpers,
|
|
1126
|
+
TLeanResultType,
|
|
1127
|
+
'findOneAndUpdate',
|
|
1128
|
+
TInstanceMethods & TVirtuals
|
|
1129
|
+
>;
|
|
1130
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1131
|
+
id: mongodb.ObjectId | any,
|
|
1132
|
+
update: UpdateQuery<TRawDocType>,
|
|
1133
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1134
|
+
): QueryWithHelpers<
|
|
1135
|
+
TLeanResultType | null,
|
|
1136
|
+
ResultDoc,
|
|
1137
|
+
TQueryHelpers,
|
|
1138
|
+
TLeanResultType,
|
|
1139
|
+
'findOneAndUpdate',
|
|
1140
|
+
TInstanceMethods & TVirtuals
|
|
1141
|
+
>;
|
|
1142
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1143
|
+
id: mongodb.ObjectId | any,
|
|
1144
|
+
update: UpdateQuery<TRawDocType>,
|
|
1145
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1146
|
+
): QueryWithHelpers<
|
|
1147
|
+
ResultDoc | null,
|
|
1148
|
+
ResultDoc,
|
|
1149
|
+
TQueryHelpers,
|
|
1150
|
+
TLeanResultType,
|
|
1151
|
+
'findOneAndUpdate',
|
|
1152
|
+
TInstanceMethods & TVirtuals
|
|
1153
|
+
>;
|
|
1154
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1155
|
+
id: mongodb.ObjectId | any,
|
|
1156
|
+
update: UpdateQuery<TRawDocType>,
|
|
1157
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1158
|
+
): QueryWithHelpers<
|
|
1159
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TLeanResultType> : ModifyResult<ResultDoc>,
|
|
1160
|
+
ResultDoc,
|
|
1161
|
+
TQueryHelpers,
|
|
1162
|
+
TLeanResultType,
|
|
1163
|
+
'findOneAndUpdate',
|
|
1164
|
+
TInstanceMethods & TVirtuals
|
|
1165
|
+
>;
|
|
1166
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1167
|
+
id: mongodb.ObjectId | any,
|
|
1168
|
+
update: UpdateQuery<TRawDocType>,
|
|
1169
|
+
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
1170
|
+
): QueryWithHelpers<
|
|
1171
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType : ResultDoc,
|
|
1172
|
+
ResultDoc,
|
|
1173
|
+
TQueryHelpers,
|
|
1174
|
+
TLeanResultType,
|
|
1175
|
+
'findOneAndUpdate',
|
|
1176
|
+
TInstanceMethods & TVirtuals
|
|
1177
|
+
>;
|
|
1178
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1179
|
+
id?: mongodb.ObjectId | any,
|
|
1180
|
+
update?: UpdateQuery<TRawDocType>,
|
|
1181
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1182
|
+
): QueryWithHelpers<
|
|
1183
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
1184
|
+
ResultDoc,
|
|
1185
|
+
TQueryHelpers,
|
|
1186
|
+
TLeanResultType,
|
|
1187
|
+
'findOneAndUpdate',
|
|
1188
|
+
TInstanceMethods & TVirtuals
|
|
1189
|
+
>;
|
|
398
1190
|
|
|
399
1191
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
400
|
-
findOneAndDelete<
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1192
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1193
|
+
filter: QueryFilter<TRawDocType>,
|
|
1194
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata?: false }
|
|
1195
|
+
): QueryWithHelpers<
|
|
1196
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
1197
|
+
THydratedDocumentType,
|
|
1198
|
+
TQueryHelpers,
|
|
1199
|
+
TLeanResultType,
|
|
1200
|
+
'findOneAndDelete',
|
|
1201
|
+
TInstanceMethods & TVirtuals,
|
|
1202
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1203
|
+
>;
|
|
1204
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1205
|
+
filter: QueryFilter<TRawDocType>,
|
|
1206
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata: true }
|
|
1207
|
+
): QueryWithHelpers<
|
|
1208
|
+
ModifyResult<ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>>,
|
|
1209
|
+
THydratedDocumentType,
|
|
1210
|
+
TQueryHelpers,
|
|
1211
|
+
TLeanResultType,
|
|
1212
|
+
'findOneAndDelete',
|
|
1213
|
+
TInstanceMethods & TVirtuals,
|
|
1214
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1215
|
+
>;
|
|
1216
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1217
|
+
filter: QueryFilter<TRawDocType>,
|
|
1218
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1219
|
+
): QueryWithHelpers<
|
|
1220
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1221
|
+
THydratedDocumentType,
|
|
1222
|
+
TQueryHelpers,
|
|
1223
|
+
TLeanResultType,
|
|
1224
|
+
'findOneAndDelete',
|
|
1225
|
+
TInstanceMethods & TVirtuals,
|
|
1226
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1227
|
+
>;
|
|
1228
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1229
|
+
filter: QueryFilter<TRawDocType>,
|
|
1230
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1231
|
+
): QueryWithHelpers<
|
|
1232
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1233
|
+
THydratedDocumentType,
|
|
1234
|
+
TQueryHelpers,
|
|
1235
|
+
TLeanResultType,
|
|
1236
|
+
'findOneAndDelete',
|
|
1237
|
+
TInstanceMethods & TVirtuals,
|
|
1238
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1239
|
+
>;
|
|
1240
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1241
|
+
filter: QueryFilter<TRawDocType>,
|
|
1242
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1243
|
+
): QueryWithHelpers<
|
|
1244
|
+
TLeanResultType | null,
|
|
1245
|
+
ResultDoc,
|
|
1246
|
+
TQueryHelpers,
|
|
1247
|
+
TLeanResultType,
|
|
1248
|
+
'findOneAndDelete',
|
|
1249
|
+
TInstanceMethods & TVirtuals
|
|
1250
|
+
>;
|
|
1251
|
+
findOneAndDelete(
|
|
1252
|
+
filter: Query<any, any>,
|
|
1253
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1254
|
+
): QueryWithHelpers<
|
|
1255
|
+
TLeanResultType | null,
|
|
1256
|
+
THydratedDocumentType,
|
|
1257
|
+
TQueryHelpers,
|
|
1258
|
+
TLeanResultType,
|
|
1259
|
+
'findOneAndDelete',
|
|
1260
|
+
TInstanceMethods & TVirtuals
|
|
1261
|
+
>;
|
|
1262
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1263
|
+
filter: QueryFilter<TRawDocType>,
|
|
1264
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1265
|
+
): QueryWithHelpers<
|
|
1266
|
+
ResultDoc | null,
|
|
1267
|
+
ResultDoc,
|
|
1268
|
+
TQueryHelpers,
|
|
1269
|
+
TLeanResultType,
|
|
1270
|
+
'findOneAndDelete',
|
|
1271
|
+
TInstanceMethods & TVirtuals
|
|
1272
|
+
>;
|
|
1273
|
+
findOneAndDelete(
|
|
1274
|
+
filter: Query<any, any>,
|
|
1275
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1276
|
+
): QueryWithHelpers<
|
|
1277
|
+
THydratedDocumentType | null,
|
|
1278
|
+
THydratedDocumentType,
|
|
1279
|
+
TQueryHelpers,
|
|
1280
|
+
TLeanResultType,
|
|
1281
|
+
'findOneAndDelete',
|
|
1282
|
+
TInstanceMethods & TVirtuals
|
|
1283
|
+
>;
|
|
1284
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1285
|
+
filter: QueryFilter<TRawDocType>,
|
|
1286
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1287
|
+
): QueryWithHelpers<
|
|
1288
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<ResultDoc>,
|
|
1289
|
+
ResultDoc,
|
|
1290
|
+
TQueryHelpers,
|
|
1291
|
+
TLeanResultType,
|
|
1292
|
+
'findOneAndDelete',
|
|
1293
|
+
TInstanceMethods & TVirtuals
|
|
1294
|
+
>;
|
|
1295
|
+
findOneAndDelete(
|
|
1296
|
+
filter: Query<any, any>,
|
|
1297
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1298
|
+
): QueryWithHelpers<
|
|
1299
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<THydratedDocumentType>,
|
|
1300
|
+
THydratedDocumentType,
|
|
1301
|
+
TQueryHelpers,
|
|
1302
|
+
TLeanResultType,
|
|
1303
|
+
'findOneAndDelete',
|
|
1304
|
+
TInstanceMethods & TVirtuals
|
|
1305
|
+
>;
|
|
1306
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1307
|
+
filter?: QueryFilter<TRawDocType> | null,
|
|
1308
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1309
|
+
): QueryWithHelpers<
|
|
1310
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
1311
|
+
ResultDoc,
|
|
1312
|
+
TQueryHelpers,
|
|
1313
|
+
TLeanResultType,
|
|
1314
|
+
'findOneAndDelete',
|
|
1315
|
+
TInstanceMethods & TVirtuals
|
|
1316
|
+
>;
|
|
1317
|
+
findOneAndDelete(
|
|
1318
|
+
filter?: Query<any, any> | null,
|
|
1319
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1320
|
+
): QueryWithHelpers<
|
|
1321
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : THydratedDocumentType | null,
|
|
1322
|
+
THydratedDocumentType,
|
|
1323
|
+
TQueryHelpers,
|
|
1324
|
+
TLeanResultType,
|
|
1325
|
+
'findOneAndDelete',
|
|
1326
|
+
TInstanceMethods & TVirtuals
|
|
1327
|
+
>;
|
|
404
1328
|
|
|
405
1329
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
406
|
-
findOneAndReplace<
|
|
407
|
-
|
|
408
|
-
|
|
1330
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1331
|
+
filter: QueryFilter<TRawDocType>,
|
|
1332
|
+
replacement: TRawDocType | AnyObject,
|
|
1333
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata?: false }
|
|
1334
|
+
): QueryWithHelpers<
|
|
1335
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
1336
|
+
THydratedDocumentType,
|
|
1337
|
+
TQueryHelpers,
|
|
1338
|
+
TLeanResultType,
|
|
1339
|
+
'findOneAndReplace',
|
|
1340
|
+
TInstanceMethods & TVirtuals,
|
|
1341
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1342
|
+
>;
|
|
1343
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1344
|
+
filter: QueryFilter<TRawDocType>,
|
|
1345
|
+
replacement: TRawDocType | AnyObject,
|
|
1346
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata: true }
|
|
1347
|
+
): QueryWithHelpers<
|
|
1348
|
+
ModifyResult<ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>>,
|
|
1349
|
+
THydratedDocumentType,
|
|
1350
|
+
TQueryHelpers,
|
|
1351
|
+
TLeanResultType,
|
|
1352
|
+
'findOneAndReplace',
|
|
1353
|
+
TInstanceMethods & TVirtuals,
|
|
1354
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1355
|
+
>;
|
|
1356
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1357
|
+
filter: QueryFilter<TRawDocType>,
|
|
1358
|
+
replacement: TRawDocType | AnyObject,
|
|
1359
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1360
|
+
): QueryWithHelpers<
|
|
1361
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1362
|
+
THydratedDocumentType,
|
|
1363
|
+
TQueryHelpers,
|
|
1364
|
+
TLeanResultType,
|
|
1365
|
+
'findOneAndReplace',
|
|
1366
|
+
TInstanceMethods & TVirtuals,
|
|
1367
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1368
|
+
>;
|
|
1369
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1370
|
+
filter: QueryFilter<TRawDocType>,
|
|
1371
|
+
replacement: TRawDocType | AnyObject,
|
|
1372
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1373
|
+
): QueryWithHelpers<
|
|
1374
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1375
|
+
THydratedDocumentType,
|
|
1376
|
+
TQueryHelpers,
|
|
1377
|
+
TLeanResultType,
|
|
1378
|
+
'findOneAndReplace',
|
|
1379
|
+
TInstanceMethods & TVirtuals,
|
|
1380
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1381
|
+
>;
|
|
1382
|
+
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1383
|
+
filter: QueryFilter<TRawDocType>,
|
|
1384
|
+
replacement: TRawDocType | AnyObject,
|
|
1385
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1386
|
+
): QueryWithHelpers<
|
|
1387
|
+
TLeanResultType | null,
|
|
1388
|
+
ResultDoc,
|
|
1389
|
+
TQueryHelpers,
|
|
1390
|
+
TLeanResultType,
|
|
1391
|
+
'findOneAndReplace',
|
|
1392
|
+
TInstanceMethods & TVirtuals
|
|
1393
|
+
>;
|
|
1394
|
+
findOneAndReplace(
|
|
1395
|
+
filter: Query<any, any>,
|
|
1396
|
+
replacement: TRawDocType | AnyObject,
|
|
1397
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1398
|
+
): QueryWithHelpers<
|
|
1399
|
+
TLeanResultType | null,
|
|
1400
|
+
THydratedDocumentType,
|
|
1401
|
+
TQueryHelpers,
|
|
1402
|
+
TLeanResultType,
|
|
1403
|
+
'findOneAndReplace',
|
|
1404
|
+
TInstanceMethods & TVirtuals
|
|
1405
|
+
>;
|
|
1406
|
+
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1407
|
+
filter: QueryFilter<TRawDocType>,
|
|
1408
|
+
replacement: TRawDocType | AnyObject,
|
|
1409
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1410
|
+
): QueryWithHelpers<
|
|
1411
|
+
ResultDoc | null,
|
|
1412
|
+
ResultDoc,
|
|
1413
|
+
TQueryHelpers,
|
|
1414
|
+
TLeanResultType,
|
|
1415
|
+
'findOneAndReplace',
|
|
1416
|
+
TInstanceMethods & TVirtuals
|
|
1417
|
+
>;
|
|
1418
|
+
findOneAndReplace(
|
|
1419
|
+
filter: Query<any, any>,
|
|
1420
|
+
replacement: TRawDocType | AnyObject,
|
|
1421
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1422
|
+
): QueryWithHelpers<
|
|
1423
|
+
THydratedDocumentType | null,
|
|
1424
|
+
THydratedDocumentType,
|
|
1425
|
+
TQueryHelpers,
|
|
1426
|
+
TLeanResultType,
|
|
1427
|
+
'findOneAndReplace',
|
|
1428
|
+
TInstanceMethods & TVirtuals
|
|
1429
|
+
>;
|
|
1430
|
+
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1431
|
+
filter: QueryFilter<TRawDocType>,
|
|
1432
|
+
replacement: TRawDocType | AnyObject,
|
|
1433
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1434
|
+
): QueryWithHelpers<
|
|
1435
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TLeanResultType> : ModifyResult<ResultDoc>,
|
|
1436
|
+
ResultDoc,
|
|
1437
|
+
TQueryHelpers,
|
|
1438
|
+
TLeanResultType,
|
|
1439
|
+
'findOneAndReplace',
|
|
1440
|
+
TInstanceMethods & TVirtuals
|
|
1441
|
+
>;
|
|
1442
|
+
findOneAndReplace(
|
|
1443
|
+
filter: Query<any, any>,
|
|
1444
|
+
replacement: TRawDocType | AnyObject,
|
|
1445
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1446
|
+
): QueryWithHelpers<
|
|
1447
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TLeanResultType> : ModifyResult<THydratedDocumentType>,
|
|
1448
|
+
THydratedDocumentType,
|
|
1449
|
+
TQueryHelpers,
|
|
1450
|
+
TLeanResultType,
|
|
1451
|
+
'findOneAndReplace',
|
|
1452
|
+
TInstanceMethods & TVirtuals
|
|
1453
|
+
>;
|
|
1454
|
+
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1455
|
+
filter: QueryFilter<TRawDocType>,
|
|
1456
|
+
replacement: TRawDocType | AnyObject,
|
|
1457
|
+
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
1458
|
+
): QueryWithHelpers<
|
|
1459
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType : ResultDoc,
|
|
1460
|
+
ResultDoc,
|
|
1461
|
+
TQueryHelpers,
|
|
1462
|
+
TLeanResultType,
|
|
1463
|
+
'findOneAndReplace',
|
|
1464
|
+
TInstanceMethods & TVirtuals
|
|
1465
|
+
>;
|
|
1466
|
+
findOneAndReplace(
|
|
1467
|
+
filter: Query<any, any>,
|
|
1468
|
+
replacement: TRawDocType | AnyObject,
|
|
1469
|
+
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
1470
|
+
): QueryWithHelpers<
|
|
1471
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType : THydratedDocumentType,
|
|
1472
|
+
THydratedDocumentType,
|
|
1473
|
+
TQueryHelpers,
|
|
1474
|
+
TLeanResultType,
|
|
1475
|
+
'findOneAndReplace',
|
|
1476
|
+
TInstanceMethods & TVirtuals
|
|
1477
|
+
>;
|
|
1478
|
+
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1479
|
+
filter?: QueryFilter<TRawDocType>,
|
|
1480
|
+
replacement?: TRawDocType | AnyObject,
|
|
1481
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1482
|
+
): QueryWithHelpers<
|
|
1483
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
1484
|
+
ResultDoc,
|
|
1485
|
+
TQueryHelpers,
|
|
1486
|
+
TLeanResultType,
|
|
1487
|
+
'findOneAndReplace',
|
|
1488
|
+
TInstanceMethods & TVirtuals
|
|
1489
|
+
>;
|
|
1490
|
+
findOneAndReplace(
|
|
1491
|
+
filter?: Query<any, any>,
|
|
1492
|
+
replacement?: TRawDocType | AnyObject,
|
|
1493
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1494
|
+
): QueryWithHelpers<
|
|
1495
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : THydratedDocumentType | null,
|
|
1496
|
+
THydratedDocumentType,
|
|
1497
|
+
TQueryHelpers,
|
|
1498
|
+
TLeanResultType,
|
|
1499
|
+
'findOneAndReplace',
|
|
1500
|
+
TInstanceMethods & TVirtuals
|
|
1501
|
+
>;
|
|
409
1502
|
|
|
410
1503
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
411
|
-
findOneAndUpdate<
|
|
412
|
-
filter:
|
|
413
|
-
update: UpdateQuery<
|
|
414
|
-
options: QueryOptions<
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
): QueryWithHelpers<
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
1504
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1505
|
+
filter: QueryFilter<TRawDocType>,
|
|
1506
|
+
update: UpdateQuery<TRawDocType>,
|
|
1507
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata?: false }
|
|
1508
|
+
): QueryWithHelpers<
|
|
1509
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
1510
|
+
THydratedDocumentType,
|
|
1511
|
+
TQueryHelpers,
|
|
1512
|
+
TLeanResultType,
|
|
1513
|
+
'findOneAndUpdate',
|
|
1514
|
+
TInstanceMethods & TVirtuals,
|
|
1515
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1516
|
+
>;
|
|
1517
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1518
|
+
filter: QueryFilter<TRawDocType>,
|
|
1519
|
+
update: UpdateQuery<TRawDocType>,
|
|
1520
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata: true }
|
|
1521
|
+
): QueryWithHelpers<
|
|
1522
|
+
ModifyResult<ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>>,
|
|
1523
|
+
THydratedDocumentType,
|
|
1524
|
+
TQueryHelpers,
|
|
1525
|
+
TLeanResultType,
|
|
1526
|
+
'findOneAndUpdate',
|
|
1527
|
+
TInstanceMethods & TVirtuals,
|
|
1528
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1529
|
+
>;
|
|
1530
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1531
|
+
filter: QueryFilter<TRawDocType>,
|
|
1532
|
+
update: UpdateQuery<TRawDocType>,
|
|
1533
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1534
|
+
): QueryWithHelpers<
|
|
1535
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1536
|
+
THydratedDocumentType,
|
|
1537
|
+
TQueryHelpers,
|
|
1538
|
+
TLeanResultType,
|
|
1539
|
+
'findOneAndUpdate',
|
|
1540
|
+
TInstanceMethods & TVirtuals,
|
|
1541
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1542
|
+
>;
|
|
1543
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1544
|
+
filter: QueryFilter<TRawDocType>,
|
|
1545
|
+
update: UpdateQuery<TRawDocType>,
|
|
1546
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1547
|
+
): QueryWithHelpers<
|
|
1548
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1549
|
+
THydratedDocumentType,
|
|
1550
|
+
TQueryHelpers,
|
|
1551
|
+
TLeanResultType,
|
|
1552
|
+
'findOneAndUpdate',
|
|
1553
|
+
TInstanceMethods & TVirtuals,
|
|
1554
|
+
ApplyProjection<TLeanResultType, Projection>
|
|
1555
|
+
>;
|
|
1556
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1557
|
+
filter: QueryFilter<TRawDocType>,
|
|
1558
|
+
update: UpdateQuery<TRawDocType>,
|
|
1559
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
|
|
1560
|
+
): QueryWithHelpers<
|
|
1561
|
+
ModifyResult<TRawDocType>,
|
|
1562
|
+
ResultDoc,
|
|
1563
|
+
TQueryHelpers,
|
|
1564
|
+
TLeanResultType,
|
|
1565
|
+
'findOneAndUpdate',
|
|
1566
|
+
TInstanceMethods & TVirtuals
|
|
1567
|
+
>;
|
|
1568
|
+
findOneAndUpdate(
|
|
1569
|
+
filter: Query<any, any>,
|
|
1570
|
+
update: UpdateQuery<TRawDocType>,
|
|
1571
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
|
|
1572
|
+
): QueryWithHelpers<
|
|
1573
|
+
ModifyResult<TRawDocType>,
|
|
1574
|
+
THydratedDocumentType,
|
|
1575
|
+
TQueryHelpers,
|
|
1576
|
+
TLeanResultType,
|
|
1577
|
+
'findOneAndUpdate',
|
|
1578
|
+
TInstanceMethods & TVirtuals
|
|
1579
|
+
>;
|
|
1580
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1581
|
+
filter: QueryFilter<TRawDocType>,
|
|
1582
|
+
update: UpdateQuery<TRawDocType>,
|
|
1583
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1584
|
+
): QueryWithHelpers<
|
|
1585
|
+
GetLeanResultType<TLeanResultType, TRawDocType, 'findOneAndUpdate'> | null,
|
|
1586
|
+
ResultDoc,
|
|
1587
|
+
TQueryHelpers,
|
|
1588
|
+
TLeanResultType,
|
|
1589
|
+
'findOneAndUpdate',
|
|
1590
|
+
TInstanceMethods & TVirtuals
|
|
1591
|
+
>;
|
|
1592
|
+
findOneAndUpdate(
|
|
1593
|
+
filter: Query<any, any>,
|
|
1594
|
+
update: UpdateQuery<TRawDocType>,
|
|
1595
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
1596
|
+
): QueryWithHelpers<
|
|
1597
|
+
GetLeanResultType<TLeanResultType, TRawDocType, 'findOneAndUpdate'> | null,
|
|
1598
|
+
THydratedDocumentType,
|
|
1599
|
+
TQueryHelpers,
|
|
1600
|
+
TLeanResultType,
|
|
1601
|
+
'findOneAndUpdate',
|
|
1602
|
+
TInstanceMethods & TVirtuals
|
|
1603
|
+
>;
|
|
1604
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1605
|
+
filter: QueryFilter<TRawDocType>,
|
|
1606
|
+
update: UpdateQuery<TRawDocType>,
|
|
1607
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1608
|
+
): QueryWithHelpers<
|
|
1609
|
+
ResultDoc | null,
|
|
1610
|
+
ResultDoc,
|
|
1611
|
+
TQueryHelpers,
|
|
1612
|
+
TLeanResultType,
|
|
1613
|
+
'findOneAndUpdate',
|
|
1614
|
+
TInstanceMethods & TVirtuals
|
|
1615
|
+
>;
|
|
1616
|
+
findOneAndUpdate(
|
|
1617
|
+
filter: Query<any, any>,
|
|
1618
|
+
update: UpdateQuery<TRawDocType>,
|
|
1619
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1620
|
+
): QueryWithHelpers<
|
|
1621
|
+
THydratedDocumentType | null,
|
|
1622
|
+
THydratedDocumentType,
|
|
1623
|
+
TQueryHelpers,
|
|
1624
|
+
TLeanResultType,
|
|
1625
|
+
'findOneAndUpdate',
|
|
1626
|
+
TInstanceMethods & TVirtuals
|
|
1627
|
+
>;
|
|
1628
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1629
|
+
filter: QueryFilter<TRawDocType>,
|
|
1630
|
+
update: UpdateQuery<TRawDocType>,
|
|
1631
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1632
|
+
): QueryWithHelpers<
|
|
1633
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TLeanResultType> : ModifyResult<ResultDoc>,
|
|
1634
|
+
ResultDoc,
|
|
1635
|
+
TQueryHelpers,
|
|
1636
|
+
TLeanResultType,
|
|
1637
|
+
'findOneAndUpdate',
|
|
1638
|
+
TInstanceMethods & TVirtuals
|
|
1639
|
+
>;
|
|
1640
|
+
findOneAndUpdate(
|
|
1641
|
+
filter: Query<any, any>,
|
|
1642
|
+
update: UpdateQuery<TRawDocType>,
|
|
1643
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
1644
|
+
): QueryWithHelpers<
|
|
1645
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TLeanResultType> : ModifyResult<THydratedDocumentType>,
|
|
1646
|
+
THydratedDocumentType,
|
|
1647
|
+
TQueryHelpers,
|
|
1648
|
+
TLeanResultType,
|
|
1649
|
+
'findOneAndUpdate',
|
|
1650
|
+
TInstanceMethods & TVirtuals
|
|
1651
|
+
>;
|
|
1652
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1653
|
+
filter: QueryFilter<TRawDocType>,
|
|
1654
|
+
update: UpdateQuery<TRawDocType>,
|
|
1655
|
+
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
1656
|
+
): QueryWithHelpers<
|
|
1657
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType : ResultDoc,
|
|
1658
|
+
ResultDoc,
|
|
1659
|
+
TQueryHelpers,
|
|
1660
|
+
TLeanResultType,
|
|
1661
|
+
'findOneAndUpdate',
|
|
1662
|
+
TInstanceMethods & TVirtuals
|
|
1663
|
+
>;
|
|
1664
|
+
findOneAndUpdate(
|
|
1665
|
+
filter: Query<any, any>,
|
|
1666
|
+
update: UpdateQuery<TRawDocType>,
|
|
1667
|
+
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
1668
|
+
): QueryWithHelpers<
|
|
1669
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType : THydratedDocumentType,
|
|
1670
|
+
THydratedDocumentType,
|
|
1671
|
+
TQueryHelpers,
|
|
1672
|
+
TLeanResultType,
|
|
1673
|
+
'findOneAndUpdate',
|
|
1674
|
+
TInstanceMethods & TVirtuals
|
|
1675
|
+
>;
|
|
1676
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1677
|
+
filter?: QueryFilter<TRawDocType>,
|
|
1678
|
+
update?: UpdateQuery<TRawDocType>,
|
|
1679
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1680
|
+
): QueryWithHelpers<
|
|
1681
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
1682
|
+
ResultDoc,
|
|
1683
|
+
TQueryHelpers,
|
|
1684
|
+
TLeanResultType,
|
|
1685
|
+
'findOneAndUpdate',
|
|
1686
|
+
TInstanceMethods & TVirtuals
|
|
1687
|
+
>;
|
|
1688
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1689
|
+
filter?: Query<any, any>,
|
|
1690
|
+
update?: UpdateQuery<TRawDocType>,
|
|
1691
|
+
options?: QueryOptions<TRawDocType> | null
|
|
1692
|
+
): QueryWithHelpers<
|
|
1693
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
1694
|
+
ResultDoc,
|
|
1695
|
+
TQueryHelpers,
|
|
1696
|
+
TLeanResultType,
|
|
1697
|
+
'findOneAndUpdate',
|
|
1698
|
+
TInstanceMethods & TVirtuals
|
|
1699
|
+
>;
|
|
444
1700
|
|
|
445
1701
|
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
|
|
446
|
-
replaceOne<ResultDoc =
|
|
447
|
-
filter?:
|
|
448
|
-
replacement?:
|
|
449
|
-
options?: QueryOptions<
|
|
450
|
-
|
|
451
|
-
|
|
1702
|
+
replaceOne<ResultDoc = THydratedDocumentType>(
|
|
1703
|
+
filter?: QueryFilter<TRawDocType>,
|
|
1704
|
+
replacement?: TRawDocType | AnyObject,
|
|
1705
|
+
options?: (mongodb.ReplaceOptions & QueryOptions<TRawDocType>) | null
|
|
1706
|
+
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TLeanResultType, 'replaceOne', TInstanceMethods & TVirtuals>;
|
|
1707
|
+
replaceOne<ResultDoc = THydratedDocumentType>(
|
|
1708
|
+
filter?: Query<any, any>,
|
|
1709
|
+
replacement?: TRawDocType | AnyObject,
|
|
1710
|
+
options?: (mongodb.ReplaceOptions & QueryOptions<TRawDocType>) | null
|
|
1711
|
+
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TLeanResultType, 'replaceOne', TInstanceMethods & TVirtuals>;
|
|
452
1712
|
|
|
453
|
-
/**
|
|
454
|
-
|
|
1713
|
+
/** Apply changes made to this model's schema after this model was compiled. */
|
|
1714
|
+
recompileSchema(): void;
|
|
455
1715
|
|
|
456
|
-
/**
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
|
|
463
|
-
options?: QueryOptions<T> | null,
|
|
464
|
-
callback?: Callback
|
|
465
|
-
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1716
|
+
/** Schema the model uses. */
|
|
1717
|
+
schema: IfAny<
|
|
1718
|
+
TSchema,
|
|
1719
|
+
Schema<TRawDocType, Model<TRawDocType, TQueryHelpers, TInstanceMethods, TVirtuals>, TInstanceMethods, TQueryHelpers, TVirtuals>,
|
|
1720
|
+
TSchema
|
|
1721
|
+
>;
|
|
466
1722
|
|
|
467
1723
|
/** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
|
|
468
|
-
updateMany
|
|
469
|
-
filter
|
|
470
|
-
update
|
|
471
|
-
options?:
|
|
472
|
-
|
|
473
|
-
|
|
1724
|
+
updateMany(
|
|
1725
|
+
filter: QueryFilter<TRawDocType>,
|
|
1726
|
+
update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
|
|
1727
|
+
options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
|
|
1728
|
+
): QueryWithHelpers<UpdateWriteOpResult, THydratedDocumentType, TQueryHelpers, TLeanResultType, 'updateMany', TInstanceMethods & TVirtuals>;
|
|
1729
|
+
updateMany(
|
|
1730
|
+
filter: Query<any, any>,
|
|
1731
|
+
update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
|
|
1732
|
+
options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
|
|
1733
|
+
): QueryWithHelpers<UpdateWriteOpResult, THydratedDocumentType, TQueryHelpers, TLeanResultType, 'updateMany', TInstanceMethods & TVirtuals>;
|
|
474
1734
|
|
|
475
1735
|
/** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
|
|
476
|
-
updateOne
|
|
477
|
-
filter
|
|
478
|
-
update
|
|
479
|
-
options?:
|
|
480
|
-
|
|
481
|
-
|
|
1736
|
+
updateOne(
|
|
1737
|
+
filter: QueryFilter<TRawDocType>,
|
|
1738
|
+
update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
|
|
1739
|
+
options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
|
|
1740
|
+
): QueryWithHelpers<UpdateWriteOpResult, THydratedDocumentType, TQueryHelpers, TLeanResultType, 'updateOne', TInstanceMethods & TVirtuals>;
|
|
1741
|
+
updateOne(
|
|
1742
|
+
filter: Query<any, any>,
|
|
1743
|
+
update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
|
|
1744
|
+
options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
|
|
1745
|
+
): QueryWithHelpers<UpdateWriteOpResult, THydratedDocumentType, TQueryHelpers, TLeanResultType, 'updateOne', TInstanceMethods & TVirtuals>;
|
|
482
1746
|
|
|
483
1747
|
/** Creates a Query, applies the passed conditions, and returns the Query. */
|
|
484
|
-
where<ResultDoc =
|
|
485
|
-
|
|
486
|
-
|
|
1748
|
+
where<ResultDoc = THydratedDocumentType>(
|
|
1749
|
+
path: string,
|
|
1750
|
+
val?: any
|
|
1751
|
+
): QueryWithHelpers<HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[], ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>;
|
|
1752
|
+
where<ResultDoc = THydratedDocumentType>(obj: object): QueryWithHelpers<
|
|
1753
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
1754
|
+
ResultDoc,
|
|
1755
|
+
TQueryHelpers,
|
|
1756
|
+
TLeanResultType,
|
|
1757
|
+
'find',
|
|
1758
|
+
TInstanceMethods & TVirtuals
|
|
1759
|
+
>;
|
|
1760
|
+
where<ResultDoc = THydratedDocumentType>(): QueryWithHelpers<
|
|
1761
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
1762
|
+
ResultDoc,
|
|
1763
|
+
TQueryHelpers,
|
|
1764
|
+
TLeanResultType,
|
|
1765
|
+
'find',
|
|
1766
|
+
TInstanceMethods & TVirtuals
|
|
1767
|
+
>;
|
|
1768
|
+
|
|
1769
|
+
/**
|
|
1770
|
+
* If auto encryption is enabled, returns a ClientEncryption instance that is configured with the same settings that
|
|
1771
|
+
* Mongoose's underlying MongoClient is using. If the client has not yet been configured, returns null.
|
|
1772
|
+
*/
|
|
1773
|
+
clientEncryption(): mongodb.ClientEncryption | null;
|
|
487
1774
|
}
|
|
488
1775
|
}
|