@datanimbus/mongoose 6.13.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +232 -0
- package/.mocharc.yml +4 -0
- package/LICENSE.md +22 -0
- package/README.md +387 -0
- package/SECURITY.md +1 -0
- package/browser.js +8 -0
- package/dist/browser.umd.js +2 -0
- package/index.js +63 -0
- package/lgtm.yml +12 -0
- package/lib/aggregate.js +1164 -0
- package/lib/browser.js +158 -0
- package/lib/browserDocument.js +101 -0
- package/lib/cast/boolean.js +32 -0
- package/lib/cast/date.js +41 -0
- package/lib/cast/decimal128.js +36 -0
- package/lib/cast/number.js +42 -0
- package/lib/cast/objectid.js +29 -0
- package/lib/cast/string.js +37 -0
- package/lib/cast.js +418 -0
- package/lib/collection.js +311 -0
- package/lib/connection.js +1574 -0
- package/lib/connectionstate.js +26 -0
- package/lib/cursor/AggregationCursor.js +380 -0
- package/lib/cursor/ChangeStream.js +154 -0
- package/lib/cursor/QueryCursor.js +538 -0
- package/lib/document.js +4771 -0
- package/lib/document_provider.js +30 -0
- package/lib/driver.js +15 -0
- package/lib/drivers/SPEC.md +4 -0
- package/lib/drivers/browser/ReadPreference.js +7 -0
- package/lib/drivers/browser/binary.js +14 -0
- package/lib/drivers/browser/decimal128.js +7 -0
- package/lib/drivers/browser/index.js +16 -0
- package/lib/drivers/browser/objectid.js +29 -0
- package/lib/drivers/node-mongodb-native/ReadPreference.js +47 -0
- package/lib/drivers/node-mongodb-native/binary.js +10 -0
- package/lib/drivers/node-mongodb-native/collection.js +460 -0
- package/lib/drivers/node-mongodb-native/connection.js +166 -0
- package/lib/drivers/node-mongodb-native/decimal128.js +7 -0
- package/lib/drivers/node-mongodb-native/index.js +12 -0
- package/lib/drivers/node-mongodb-native/objectid.js +16 -0
- package/lib/error/browserMissingSchema.js +28 -0
- package/lib/error/bulkWriteError.js +41 -0
- package/lib/error/cast.js +158 -0
- package/lib/error/disconnected.js +33 -0
- package/lib/error/divergentArray.js +38 -0
- package/lib/error/eachAsyncMultiError.js +41 -0
- package/lib/error/index.js +228 -0
- package/lib/error/messages.js +47 -0
- package/lib/error/missingSchema.js +31 -0
- package/lib/error/mongooseError.js +13 -0
- package/lib/error/notFound.js +45 -0
- package/lib/error/objectExpected.js +30 -0
- package/lib/error/objectParameter.js +30 -0
- package/lib/error/overwriteModel.js +30 -0
- package/lib/error/parallelSave.js +30 -0
- package/lib/error/parallelValidate.js +31 -0
- package/lib/error/serverSelection.js +61 -0
- package/lib/error/setOptionError.js +101 -0
- package/lib/error/strict.js +33 -0
- package/lib/error/strictPopulate.js +29 -0
- package/lib/error/syncIndexes.js +30 -0
- package/lib/error/validation.js +103 -0
- package/lib/error/validator.js +99 -0
- package/lib/error/version.js +36 -0
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +39 -0
- package/lib/helpers/aggregate/stringifyFunctionOperators.js +50 -0
- package/lib/helpers/arrayDepth.js +33 -0
- package/lib/helpers/clone.js +177 -0
- package/lib/helpers/common.js +127 -0
- package/lib/helpers/cursor/eachAsync.js +222 -0
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +16 -0
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +12 -0
- package/lib/helpers/discriminator/getConstructor.js +26 -0
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +28 -0
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +27 -0
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +64 -0
- package/lib/helpers/document/applyDefaults.js +128 -0
- package/lib/helpers/document/cleanModifiedSubpaths.js +35 -0
- package/lib/helpers/document/compile.js +237 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +50 -0
- package/lib/helpers/document/handleSpreadDoc.js +35 -0
- package/lib/helpers/each.js +25 -0
- package/lib/helpers/error/combinePathErrors.js +22 -0
- package/lib/helpers/firstKey.js +8 -0
- package/lib/helpers/get.js +65 -0
- package/lib/helpers/getConstructorName.js +16 -0
- package/lib/helpers/getDefaultBulkwriteResult.js +27 -0
- package/lib/helpers/getFunctionName.js +10 -0
- package/lib/helpers/immediate.js +16 -0
- package/lib/helpers/indexes/applySchemaCollation.js +13 -0
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
- package/lib/helpers/indexes/getRelatedIndexes.js +59 -0
- package/lib/helpers/indexes/isDefaultIdIndex.js +18 -0
- package/lib/helpers/indexes/isIndexEqual.js +96 -0
- package/lib/helpers/indexes/isTextIndex.js +16 -0
- package/lib/helpers/isAsyncFunction.js +9 -0
- package/lib/helpers/isBsonType.js +16 -0
- package/lib/helpers/isMongooseObject.js +22 -0
- package/lib/helpers/isObject.js +16 -0
- package/lib/helpers/isPromise.js +6 -0
- package/lib/helpers/isSimpleValidator.js +22 -0
- package/lib/helpers/model/applyDefaultsToPOJO.js +52 -0
- package/lib/helpers/model/applyHooks.js +149 -0
- package/lib/helpers/model/applyMethods.js +70 -0
- package/lib/helpers/model/applyStaticHooks.js +71 -0
- package/lib/helpers/model/applyStatics.js +13 -0
- package/lib/helpers/model/castBulkWrite.js +240 -0
- package/lib/helpers/model/discriminator.js +218 -0
- package/lib/helpers/model/pushNestedArrayPaths.js +15 -0
- package/lib/helpers/once.js +12 -0
- package/lib/helpers/parallelLimit.js +55 -0
- package/lib/helpers/path/parentPaths.js +18 -0
- package/lib/helpers/path/setDottedPath.js +33 -0
- package/lib/helpers/pluralize.js +94 -0
- package/lib/helpers/populate/SkipPopulateValue.js +10 -0
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +124 -0
- package/lib/helpers/populate/assignVals.js +337 -0
- package/lib/helpers/populate/createPopulateQueryFilter.js +97 -0
- package/lib/helpers/populate/getModelsMapForPopulate.js +756 -0
- package/lib/helpers/populate/getSchemaTypes.js +233 -0
- package/lib/helpers/populate/getVirtual.js +72 -0
- package/lib/helpers/populate/leanPopulateMap.js +7 -0
- package/lib/helpers/populate/lookupLocalFields.js +40 -0
- package/lib/helpers/populate/markArraySubdocsPopulated.js +47 -0
- package/lib/helpers/populate/modelNamesFromRefPath.js +68 -0
- package/lib/helpers/populate/removeDeselectedForeignField.js +31 -0
- package/lib/helpers/populate/validateRef.js +19 -0
- package/lib/helpers/printJestWarning.js +21 -0
- package/lib/helpers/printStrictQueryWarning.js +11 -0
- package/lib/helpers/processConnectionOptions.js +65 -0
- package/lib/helpers/projection/applyProjection.js +77 -0
- package/lib/helpers/projection/hasIncludedChildren.js +41 -0
- package/lib/helpers/projection/isDefiningProjection.js +18 -0
- package/lib/helpers/projection/isExclusive.js +35 -0
- package/lib/helpers/projection/isInclusive.js +38 -0
- package/lib/helpers/projection/isNestedProjection.js +8 -0
- package/lib/helpers/projection/isPathExcluded.js +40 -0
- package/lib/helpers/projection/isPathSelectedInclusive.js +28 -0
- package/lib/helpers/projection/isSubpath.js +14 -0
- package/lib/helpers/projection/parseProjection.js +33 -0
- package/lib/helpers/promiseOrCallback.js +55 -0
- package/lib/helpers/query/applyGlobalOption.js +29 -0
- package/lib/helpers/query/applyQueryMiddleware.js +79 -0
- package/lib/helpers/query/cast$expr.js +282 -0
- package/lib/helpers/query/castFilterPath.js +54 -0
- package/lib/helpers/query/castUpdate.js +560 -0
- package/lib/helpers/query/completeMany.js +52 -0
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +90 -0
- package/lib/helpers/query/handleImmutable.js +28 -0
- package/lib/helpers/query/hasDollarKeys.js +23 -0
- package/lib/helpers/query/isOperator.js +14 -0
- package/lib/helpers/query/sanitizeFilter.js +38 -0
- package/lib/helpers/query/sanitizeProjection.js +14 -0
- package/lib/helpers/query/selectPopulatedFields.js +49 -0
- package/lib/helpers/query/trusted.js +13 -0
- package/lib/helpers/query/validOps.js +24 -0
- package/lib/helpers/query/wrapThunk.js +31 -0
- package/lib/helpers/schema/addAutoId.js +7 -0
- package/lib/helpers/schema/applyBuiltinPlugins.js +12 -0
- package/lib/helpers/schema/applyPlugins.js +55 -0
- package/lib/helpers/schema/applyWriteConcern.js +30 -0
- package/lib/helpers/schema/cleanPositionalOperators.js +12 -0
- package/lib/helpers/schema/getIndexes.js +164 -0
- package/lib/helpers/schema/getKeysInSchemaOrder.js +28 -0
- package/lib/helpers/schema/getPath.js +37 -0
- package/lib/helpers/schema/handleIdOption.js +20 -0
- package/lib/helpers/schema/handleTimestampOption.js +24 -0
- package/lib/helpers/schema/idGetter.js +32 -0
- package/lib/helpers/schema/merge.js +28 -0
- package/lib/helpers/schematype/handleImmutable.js +50 -0
- package/lib/helpers/setDefaultsOnInsert.js +132 -0
- package/lib/helpers/specialProperties.js +3 -0
- package/lib/helpers/symbols.js +20 -0
- package/lib/helpers/timers.js +3 -0
- package/lib/helpers/timestamps/setDocumentTimestamps.js +26 -0
- package/lib/helpers/timestamps/setupTimestamps.js +101 -0
- package/lib/helpers/topology/allServersUnknown.js +12 -0
- package/lib/helpers/topology/isAtlas.js +31 -0
- package/lib/helpers/topology/isSSLError.js +16 -0
- package/lib/helpers/update/applyTimestampsToChildren.js +193 -0
- package/lib/helpers/update/applyTimestampsToUpdate.js +117 -0
- package/lib/helpers/update/castArrayFilters.js +109 -0
- package/lib/helpers/update/modifiedPaths.js +33 -0
- package/lib/helpers/update/moveImmutableProperties.js +53 -0
- package/lib/helpers/update/removeUnusedArrayFilters.js +32 -0
- package/lib/helpers/update/updatedPathsByArrayFilter.js +27 -0
- package/lib/helpers/updateValidators.js +249 -0
- package/lib/index.js +1338 -0
- package/lib/internal.js +46 -0
- package/lib/model.js +5474 -0
- package/lib/options/PopulateOptions.js +36 -0
- package/lib/options/SchemaArrayOptions.js +78 -0
- package/lib/options/SchemaBufferOptions.js +38 -0
- package/lib/options/SchemaDateOptions.js +71 -0
- package/lib/options/SchemaDocumentArrayOptions.js +68 -0
- package/lib/options/SchemaMapOptions.js +43 -0
- package/lib/options/SchemaNumberOptions.js +101 -0
- package/lib/options/SchemaObjectIdOptions.js +64 -0
- package/lib/options/SchemaStringOptions.js +138 -0
- package/lib/options/SchemaSubdocumentOptions.js +42 -0
- package/lib/options/SchemaTypeOptions.js +244 -0
- package/lib/options/VirtualOptions.js +164 -0
- package/lib/options/propertyOptions.js +8 -0
- package/lib/options/removeOptions.js +14 -0
- package/lib/options/saveOptions.js +14 -0
- package/lib/options.js +15 -0
- package/lib/plugins/index.js +7 -0
- package/lib/plugins/removeSubdocs.js +31 -0
- package/lib/plugins/saveSubdocs.js +66 -0
- package/lib/plugins/sharding.js +83 -0
- package/lib/plugins/trackTransaction.js +92 -0
- package/lib/plugins/validateBeforeSave.js +45 -0
- package/lib/promise_provider.js +49 -0
- package/lib/query.js +5982 -0
- package/lib/queryhelpers.js +353 -0
- package/lib/schema/DocumentArrayElement.js +100 -0
- package/lib/schema/SubdocumentPath.js +369 -0
- package/lib/schema/array.js +663 -0
- package/lib/schema/boolean.js +267 -0
- package/lib/schema/buffer.js +269 -0
- package/lib/schema/date.js +404 -0
- package/lib/schema/decimal128.js +210 -0
- package/lib/schema/documentarray.js +598 -0
- package/lib/schema/index.js +39 -0
- package/lib/schema/map.js +84 -0
- package/lib/schema/mixed.js +132 -0
- package/lib/schema/number.js +438 -0
- package/lib/schema/objectid.js +295 -0
- package/lib/schema/operators/bitwise.js +38 -0
- package/lib/schema/operators/exists.js +12 -0
- package/lib/schema/operators/geospatial.js +107 -0
- package/lib/schema/operators/helpers.js +32 -0
- package/lib/schema/operators/text.js +39 -0
- package/lib/schema/operators/type.js +20 -0
- package/lib/schema/string.js +694 -0
- package/lib/schema/symbols.js +5 -0
- package/lib/schema/uuid.js +334 -0
- package/lib/schema.js +2665 -0
- package/lib/schematype.js +1727 -0
- package/lib/statemachine.js +207 -0
- package/lib/types/ArraySubdocument.js +189 -0
- package/lib/types/DocumentArray/index.js +113 -0
- package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
- package/lib/types/DocumentArray/methods/index.js +383 -0
- package/lib/types/array/index.js +116 -0
- package/lib/types/array/isMongooseArray.js +5 -0
- package/lib/types/array/methods/index.js +1014 -0
- package/lib/types/buffer.js +277 -0
- package/lib/types/decimal128.js +13 -0
- package/lib/types/index.js +20 -0
- package/lib/types/map.js +354 -0
- package/lib/types/objectid.js +41 -0
- package/lib/types/subdocument.js +432 -0
- package/lib/utils.js +1011 -0
- package/lib/validoptions.js +36 -0
- package/lib/virtualtype.js +175 -0
- package/package.json +164 -0
- package/scripts/build-browser.js +18 -0
- package/scripts/create-tarball.js +7 -0
- package/scripts/generateSearch.js +154 -0
- package/scripts/tsc-diagnostics-check.js +15 -0
- package/tools/auth.js +31 -0
- package/tools/repl.js +35 -0
- package/tools/sharded.js +46 -0
- package/tsconfig.json +9 -0
- package/types/aggregate.d.ts +174 -0
- package/types/augmentations.d.ts +9 -0
- package/types/callback.d.ts +8 -0
- package/types/collection.d.ts +44 -0
- package/types/connection.d.ts +242 -0
- package/types/cursor.d.ts +62 -0
- package/types/document.d.ts +266 -0
- package/types/error.d.ts +138 -0
- package/types/expressions.d.ts +2936 -0
- package/types/helpers.d.ts +32 -0
- package/types/index.d.ts +627 -0
- package/types/indexes.d.ts +98 -0
- package/types/inferschematype.d.ts +228 -0
- package/types/middlewares.d.ts +32 -0
- package/types/models.d.ts +488 -0
- package/types/mongooseoptions.d.ts +206 -0
- package/types/pipelinestage.d.ts +297 -0
- package/types/populate.d.ts +45 -0
- package/types/query.d.ts +659 -0
- package/types/schemaoptions.d.ts +231 -0
- package/types/schematypes.d.ts +478 -0
- package/types/session.d.ts +36 -0
- package/types/types.d.ts +104 -0
- package/types/utility.d.ts +43 -0
- package/types/validation.d.ts +34 -0
- package/types/virtuals.d.ts +14 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* Module dependencies.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const Binary = require('../driver').get().Binary;
|
|
8
|
+
const isBsonType = require('./isBsonType');
|
|
9
|
+
const isMongooseObject = require('./isMongooseObject');
|
|
10
|
+
const MongooseError = require('../error');
|
|
11
|
+
const util = require('util');
|
|
12
|
+
|
|
13
|
+
exports.flatten = flatten;
|
|
14
|
+
exports.modifiedPaths = modifiedPaths;
|
|
15
|
+
|
|
16
|
+
/*!
|
|
17
|
+
* ignore
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function flatten(update, path, options, schema) {
|
|
21
|
+
let keys;
|
|
22
|
+
if (update && isMongooseObject(update) && !Buffer.isBuffer(update)) {
|
|
23
|
+
keys = Object.keys(update.toObject({ transform: false, virtuals: false }) || {});
|
|
24
|
+
} else {
|
|
25
|
+
keys = Object.keys(update || {});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const numKeys = keys.length;
|
|
29
|
+
const result = {};
|
|
30
|
+
path = path ? path + '.' : '';
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < numKeys; ++i) {
|
|
33
|
+
const key = keys[i];
|
|
34
|
+
const val = update[key];
|
|
35
|
+
result[path + key] = val;
|
|
36
|
+
|
|
37
|
+
// Avoid going into mixed paths if schema is specified
|
|
38
|
+
const keySchema = schema && schema.path && schema.path(path + key);
|
|
39
|
+
const isNested = schema && schema.nested && schema.nested[path + key];
|
|
40
|
+
if (keySchema && keySchema.instance === 'Mixed') continue;
|
|
41
|
+
|
|
42
|
+
if (shouldFlatten(val)) {
|
|
43
|
+
if (options && options.skipArrays && Array.isArray(val)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const flat = flatten(val, path + key, options, schema);
|
|
47
|
+
for (const k in flat) {
|
|
48
|
+
result[k] = flat[k];
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(val)) {
|
|
51
|
+
result[path + key] = val;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isNested) {
|
|
56
|
+
const paths = Object.keys(schema.paths);
|
|
57
|
+
for (const p of paths) {
|
|
58
|
+
if (p.startsWith(path + key + '.') && !result.hasOwnProperty(p)) {
|
|
59
|
+
result[p] = void 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*!
|
|
69
|
+
* ignore
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
function modifiedPaths(update, path, result, recursion = null) {
|
|
73
|
+
if (update == null || typeof update !== 'object') {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (recursion == null) {
|
|
78
|
+
recursion = {
|
|
79
|
+
raw: { update, path },
|
|
80
|
+
trace: new WeakSet()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (recursion.trace.has(update)) {
|
|
85
|
+
throw new MongooseError(`a circular reference in the update value, updateValue:
|
|
86
|
+
${util.inspect(recursion.raw.update, { showHidden: false, depth: 1 })}
|
|
87
|
+
updatePath: '${recursion.raw.path}'`);
|
|
88
|
+
}
|
|
89
|
+
recursion.trace.add(update);
|
|
90
|
+
|
|
91
|
+
const keys = Object.keys(update || {});
|
|
92
|
+
const numKeys = keys.length;
|
|
93
|
+
result = result || {};
|
|
94
|
+
path = path ? path + '.' : '';
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < numKeys; ++i) {
|
|
97
|
+
const key = keys[i];
|
|
98
|
+
let val = update[key];
|
|
99
|
+
|
|
100
|
+
const _path = path + key;
|
|
101
|
+
result[_path] = true;
|
|
102
|
+
if (!Buffer.isBuffer(val) && isMongooseObject(val)) {
|
|
103
|
+
val = val.toObject({ transform: false, virtuals: false });
|
|
104
|
+
}
|
|
105
|
+
if (shouldFlatten(val)) {
|
|
106
|
+
modifiedPaths(val, path + key, result, recursion);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
recursion.trace.delete(update);
|
|
110
|
+
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/*!
|
|
115
|
+
* ignore
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
function shouldFlatten(val) {
|
|
119
|
+
return val &&
|
|
120
|
+
typeof val === 'object' &&
|
|
121
|
+
!(val instanceof Date) &&
|
|
122
|
+
!isBsonType(val, 'ObjectID') &&
|
|
123
|
+
(!Array.isArray(val) || val.length !== 0) &&
|
|
124
|
+
!(val instanceof Buffer) &&
|
|
125
|
+
!isBsonType(val, 'Decimal128') &&
|
|
126
|
+
!(val instanceof Binary);
|
|
127
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* Module dependencies.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const EachAsyncMultiError = require('../../error/eachAsyncMultiError');
|
|
8
|
+
const immediate = require('../immediate');
|
|
9
|
+
const promiseOrCallback = require('../promiseOrCallback');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Execute `fn` for every document in the cursor. If `fn` returns a promise,
|
|
13
|
+
* will wait for the promise to resolve before iterating on to the next one.
|
|
14
|
+
* Returns a promise that resolves when done.
|
|
15
|
+
*
|
|
16
|
+
* @param {Function} next the thunk to call to get the next document
|
|
17
|
+
* @param {Function} fn
|
|
18
|
+
* @param {Object} options
|
|
19
|
+
* @param {Number} [options.batchSize=null] if set, Mongoose will call `fn` with an array of at most `batchSize` documents, instead of a single document
|
|
20
|
+
* @param {Number} [options.parallel=1] maximum number of `fn` calls that Mongoose will run in parallel
|
|
21
|
+
* @param {AbortSignal} [options.signal] allow cancelling this eachAsync(). Once the abort signal is fired, `eachAsync()` will immediately fulfill the returned promise (or call the callback) and not fetch any more documents.
|
|
22
|
+
* @param {Function} [callback] executed when all docs have been processed
|
|
23
|
+
* @return {Promise}
|
|
24
|
+
* @api public
|
|
25
|
+
* @method eachAsync
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
module.exports = function eachAsync(next, fn, options, callback) {
|
|
29
|
+
const parallel = options.parallel || 1;
|
|
30
|
+
const batchSize = options.batchSize;
|
|
31
|
+
const signal = options.signal;
|
|
32
|
+
const continueOnError = options.continueOnError;
|
|
33
|
+
const aggregatedErrors = [];
|
|
34
|
+
const enqueue = asyncQueue();
|
|
35
|
+
|
|
36
|
+
let aborted = false;
|
|
37
|
+
|
|
38
|
+
return promiseOrCallback(callback, cb => {
|
|
39
|
+
if (signal != null) {
|
|
40
|
+
if (signal.aborted) {
|
|
41
|
+
return cb(null);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
signal.addEventListener('abort', () => {
|
|
45
|
+
aborted = true;
|
|
46
|
+
return cb(null);
|
|
47
|
+
}, { once: true });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (batchSize != null) {
|
|
51
|
+
if (typeof batchSize !== 'number') {
|
|
52
|
+
throw new TypeError('batchSize must be a number');
|
|
53
|
+
} else if (!Number.isInteger(batchSize)) {
|
|
54
|
+
throw new TypeError('batchSize must be an integer');
|
|
55
|
+
} else if (batchSize < 1) {
|
|
56
|
+
throw new TypeError('batchSize must be at least 1');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
iterate(cb);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
function iterate(finalCallback) {
|
|
64
|
+
let handleResultsInProgress = 0;
|
|
65
|
+
let currentDocumentIndex = 0;
|
|
66
|
+
|
|
67
|
+
let error = null;
|
|
68
|
+
for (let i = 0; i < parallel; ++i) {
|
|
69
|
+
enqueue(createFetch());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function createFetch() {
|
|
73
|
+
let documentsBatch = [];
|
|
74
|
+
let drained = false;
|
|
75
|
+
|
|
76
|
+
return fetch;
|
|
77
|
+
|
|
78
|
+
function fetch(done) {
|
|
79
|
+
if (drained || aborted) {
|
|
80
|
+
return done();
|
|
81
|
+
} else if (error) {
|
|
82
|
+
return done();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
next(function(err, doc) {
|
|
86
|
+
if (error != null) {
|
|
87
|
+
return done();
|
|
88
|
+
}
|
|
89
|
+
if (err != null) {
|
|
90
|
+
if (err.name === 'MongoCursorExhaustedError') {
|
|
91
|
+
// We may end up calling `next()` multiple times on an exhausted
|
|
92
|
+
// cursor, which leads to an error. In case cursor is exhausted,
|
|
93
|
+
// just treat it as if the cursor returned no document, which is
|
|
94
|
+
// how a cursor indicates it is exhausted.
|
|
95
|
+
doc = null;
|
|
96
|
+
} else if (continueOnError) {
|
|
97
|
+
aggregatedErrors.push(err);
|
|
98
|
+
} else {
|
|
99
|
+
error = err;
|
|
100
|
+
finalCallback(err);
|
|
101
|
+
return done();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (doc == null) {
|
|
105
|
+
drained = true;
|
|
106
|
+
if (handleResultsInProgress <= 0) {
|
|
107
|
+
const finalErr = continueOnError ?
|
|
108
|
+
createEachAsyncMultiError(aggregatedErrors) :
|
|
109
|
+
error;
|
|
110
|
+
|
|
111
|
+
finalCallback(finalErr);
|
|
112
|
+
} else if (batchSize && documentsBatch.length) {
|
|
113
|
+
handleNextResult(documentsBatch, currentDocumentIndex++, handleNextResultCallBack);
|
|
114
|
+
}
|
|
115
|
+
return done();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
++handleResultsInProgress;
|
|
119
|
+
|
|
120
|
+
// Kick off the subsequent `next()` before handling the result, but
|
|
121
|
+
// make sure we know that we still have a result to handle re: #8422
|
|
122
|
+
immediate(() => done());
|
|
123
|
+
|
|
124
|
+
if (batchSize) {
|
|
125
|
+
documentsBatch.push(doc);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// If the current documents size is less than the provided batch size don't process the documents yet
|
|
129
|
+
if (batchSize && documentsBatch.length !== batchSize) {
|
|
130
|
+
immediate(() => enqueue(fetch));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const docsToProcess = batchSize ? documentsBatch : doc;
|
|
135
|
+
|
|
136
|
+
function handleNextResultCallBack(err) {
|
|
137
|
+
if (batchSize) {
|
|
138
|
+
handleResultsInProgress -= documentsBatch.length;
|
|
139
|
+
documentsBatch = [];
|
|
140
|
+
} else {
|
|
141
|
+
--handleResultsInProgress;
|
|
142
|
+
}
|
|
143
|
+
if (err != null) {
|
|
144
|
+
if (continueOnError) {
|
|
145
|
+
aggregatedErrors.push(err);
|
|
146
|
+
} else {
|
|
147
|
+
error = err;
|
|
148
|
+
return finalCallback(err);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if ((drained || aborted) && handleResultsInProgress <= 0) {
|
|
152
|
+
const finalErr = continueOnError ?
|
|
153
|
+
createEachAsyncMultiError(aggregatedErrors) :
|
|
154
|
+
error;
|
|
155
|
+
return finalCallback(finalErr);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
immediate(() => enqueue(fetch));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
handleNextResult(docsToProcess, currentDocumentIndex++, handleNextResultCallBack);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function handleNextResult(doc, i, callback) {
|
|
168
|
+
let maybePromise;
|
|
169
|
+
try {
|
|
170
|
+
maybePromise = fn(doc, i);
|
|
171
|
+
} catch (err) {
|
|
172
|
+
return callback(err);
|
|
173
|
+
}
|
|
174
|
+
if (maybePromise && typeof maybePromise.then === 'function') {
|
|
175
|
+
maybePromise.then(
|
|
176
|
+
function() { callback(null); },
|
|
177
|
+
function(error) {
|
|
178
|
+
callback(error || new Error('`eachAsync()` promise rejected without error'));
|
|
179
|
+
});
|
|
180
|
+
} else {
|
|
181
|
+
callback(null);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// `next()` can only execute one at a time, so make sure we always execute
|
|
187
|
+
// `next()` in series, while still allowing multiple `fn()` instances to run
|
|
188
|
+
// in parallel.
|
|
189
|
+
function asyncQueue() {
|
|
190
|
+
const _queue = [];
|
|
191
|
+
let inProgress = null;
|
|
192
|
+
let id = 0;
|
|
193
|
+
|
|
194
|
+
return function enqueue(fn) {
|
|
195
|
+
if (
|
|
196
|
+
inProgress === null &&
|
|
197
|
+
_queue.length === 0
|
|
198
|
+
) {
|
|
199
|
+
inProgress = id++;
|
|
200
|
+
return fn(_step);
|
|
201
|
+
}
|
|
202
|
+
_queue.push(fn);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
function _step() {
|
|
206
|
+
if (_queue.length !== 0) {
|
|
207
|
+
inProgress = id++;
|
|
208
|
+
const fn = _queue.shift();
|
|
209
|
+
fn(_step);
|
|
210
|
+
} else {
|
|
211
|
+
inProgress = null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function createEachAsyncMultiError(aggregatedErrors) {
|
|
217
|
+
if (aggregatedErrors.length === 0) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return new EachAsyncMultiError(aggregatedErrors);
|
|
222
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isBsonType = require('../isBsonType');
|
|
4
|
+
|
|
5
|
+
module.exports = function areDiscriminatorValuesEqual(a, b) {
|
|
6
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
7
|
+
return a === b;
|
|
8
|
+
}
|
|
9
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
10
|
+
return a === b;
|
|
11
|
+
}
|
|
12
|
+
if (isBsonType(a, 'ObjectID') && isBsonType(b, 'ObjectID')) {
|
|
13
|
+
return a.toString() === b.toString();
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection, path, schema, selected, addedPaths) {
|
|
4
|
+
const userProjectedInPath = Object.keys(userProjection).
|
|
5
|
+
reduce((cur, key) => cur || key.startsWith(path + '.'), false);
|
|
6
|
+
const _discriminatorKey = path + '.' + schema.options.discriminatorKey;
|
|
7
|
+
if (!userProjectedInPath &&
|
|
8
|
+
addedPaths.length === 1 &&
|
|
9
|
+
addedPaths[0] === _discriminatorKey) {
|
|
10
|
+
selected.splice(selected.indexOf(_discriminatorKey), 1);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getDiscriminatorByValue = require('./getDiscriminatorByValue');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Find the correct constructor, taking into account discriminators
|
|
7
|
+
* @api private
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
module.exports = function getConstructor(Constructor, value) {
|
|
11
|
+
const discriminatorKey = Constructor.schema.options.discriminatorKey;
|
|
12
|
+
if (value != null &&
|
|
13
|
+
Constructor.discriminators &&
|
|
14
|
+
value[discriminatorKey] != null) {
|
|
15
|
+
if (Constructor.discriminators[value[discriminatorKey]]) {
|
|
16
|
+
Constructor = Constructor.discriminators[value[discriminatorKey]];
|
|
17
|
+
} else {
|
|
18
|
+
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
|
|
19
|
+
if (constructorByValue) {
|
|
20
|
+
Constructor = constructorByValue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Constructor;
|
|
26
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* returns discriminator by discriminatorMapping.value
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} discriminators
|
|
9
|
+
* @param {string} value
|
|
10
|
+
* @api private
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
module.exports = function getDiscriminatorByValue(discriminators, value) {
|
|
14
|
+
if (discriminators == null) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
for (const name of Object.keys(discriminators)) {
|
|
18
|
+
const it = discriminators[name];
|
|
19
|
+
if (
|
|
20
|
+
it.schema &&
|
|
21
|
+
it.schema.discriminatorMapping &&
|
|
22
|
+
areDiscriminatorValuesEqual(it.schema.discriminatorMapping.value, value)
|
|
23
|
+
) {
|
|
24
|
+
return it;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* returns discriminator by discriminatorMapping.value
|
|
7
|
+
*
|
|
8
|
+
* @param {Schema} schema
|
|
9
|
+
* @param {string} value
|
|
10
|
+
* @api private
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
module.exports = function getSchemaDiscriminatorByValue(schema, value) {
|
|
14
|
+
if (schema == null || schema.discriminators == null) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
for (const key of Object.keys(schema.discriminators)) {
|
|
18
|
+
const discriminatorSchema = schema.discriminators[key];
|
|
19
|
+
if (discriminatorSchema.discriminatorMapping == null) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (areDiscriminatorValuesEqual(discriminatorSchema.discriminatorMapping.value, value)) {
|
|
23
|
+
return discriminatorSchema;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const schemaMerge = require('../schema/merge');
|
|
3
|
+
const specialProperties = require('../../helpers/specialProperties');
|
|
4
|
+
const isBsonType = require('../../helpers/isBsonType');
|
|
5
|
+
const ObjectId = require('../../types/objectid');
|
|
6
|
+
const isObject = require('../../helpers/isObject');
|
|
7
|
+
/**
|
|
8
|
+
* Merges `from` into `to` without overwriting existing properties.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} to
|
|
11
|
+
* @param {Object} from
|
|
12
|
+
* @param {String} [path]
|
|
13
|
+
* @api private
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
module.exports = function mergeDiscriminatorSchema(to, from, path) {
|
|
17
|
+
const keys = Object.keys(from);
|
|
18
|
+
let i = 0;
|
|
19
|
+
const len = keys.length;
|
|
20
|
+
let key;
|
|
21
|
+
|
|
22
|
+
path = path || '';
|
|
23
|
+
|
|
24
|
+
while (i < len) {
|
|
25
|
+
key = keys[i++];
|
|
26
|
+
if (key === 'discriminators' || key === 'base' || key === '_applyDiscriminators') {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (path === 'tree' && from != null && from.instanceOfSchema) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (specialProperties.has(key)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (to[key] == null) {
|
|
36
|
+
to[key] = from[key];
|
|
37
|
+
} else if (isObject(from[key])) {
|
|
38
|
+
if (!isObject(to[key])) {
|
|
39
|
+
to[key] = {};
|
|
40
|
+
}
|
|
41
|
+
if (from[key] != null) {
|
|
42
|
+
// Skip merging schemas if we're creating a discriminator schema and
|
|
43
|
+
// base schema has a given path as a single nested but discriminator schema
|
|
44
|
+
// has the path as a document array, or vice versa (gh-9534)
|
|
45
|
+
if ((from[key].$isSingleNested && to[key].$isMongooseDocumentArray) ||
|
|
46
|
+
(from[key].$isMongooseDocumentArray && to[key].$isSingleNested) ||
|
|
47
|
+
(from[key].$isMongooseDocumentArrayElement && to[key].$isMongooseDocumentArrayElement)) {
|
|
48
|
+
continue;
|
|
49
|
+
} else if (from[key].instanceOfSchema) {
|
|
50
|
+
if (to[key].instanceOfSchema) {
|
|
51
|
+
schemaMerge(to[key], from[key].clone(), true);
|
|
52
|
+
} else {
|
|
53
|
+
to[key] = from[key].clone();
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
} else if (isBsonType(from[key], 'ObjectID')) {
|
|
57
|
+
to[key] = new ObjectId(from[key]);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
mergeDiscriminatorSchema(to[key], from[key], path ? path + '.' + key : key);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isNestedProjection = require('../projection/isNestedProjection');
|
|
4
|
+
|
|
5
|
+
module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildren, isBeforeSetters, pathsToSkip) {
|
|
6
|
+
const paths = Object.keys(doc.$__schema.paths);
|
|
7
|
+
const plen = paths.length;
|
|
8
|
+
|
|
9
|
+
for (let i = 0; i < plen; ++i) {
|
|
10
|
+
let def;
|
|
11
|
+
let curPath = '';
|
|
12
|
+
const p = paths[i];
|
|
13
|
+
|
|
14
|
+
if (p === '_id' && doc.$__.skipId) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const type = doc.$__schema.paths[p];
|
|
19
|
+
const path = type.splitPath();
|
|
20
|
+
const len = path.length;
|
|
21
|
+
let included = false;
|
|
22
|
+
let doc_ = doc._doc;
|
|
23
|
+
for (let j = 0; j < len; ++j) {
|
|
24
|
+
if (doc_ == null) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const piece = path[j];
|
|
29
|
+
curPath += (!curPath.length ? '' : '.') + piece;
|
|
30
|
+
|
|
31
|
+
if (exclude === true) {
|
|
32
|
+
if (curPath in fields) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
} else if (exclude === false && fields && !included) {
|
|
36
|
+
const hasSubpaths = type.$isSingleNested || type.$isMongooseDocumentArray;
|
|
37
|
+
if ((curPath in fields && !isNestedProjection(fields[curPath])) || (j === len - 1 && hasSubpaths && hasIncludedChildren != null && hasIncludedChildren[curPath])) {
|
|
38
|
+
included = true;
|
|
39
|
+
} else if (hasIncludedChildren != null && !hasIncludedChildren[curPath]) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (j === len - 1) {
|
|
45
|
+
if (doc_[piece] !== void 0) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (isBeforeSetters != null) {
|
|
50
|
+
if (typeof type.defaultValue === 'function') {
|
|
51
|
+
if (!type.defaultValue.$runBeforeSetters && isBeforeSetters) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (type.defaultValue.$runBeforeSetters && !isBeforeSetters) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
} else if (!isBeforeSetters) {
|
|
58
|
+
// Non-function defaults should always run **before** setters
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (pathsToSkip && pathsToSkip[curPath]) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (fields && exclude !== null) {
|
|
68
|
+
if (exclude === true) {
|
|
69
|
+
// apply defaults to all non-excluded fields
|
|
70
|
+
if (p in fields) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
def = type.getDefault(doc, false);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
doc.invalidate(p, err);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (typeof def !== 'undefined') {
|
|
82
|
+
doc_[piece] = def;
|
|
83
|
+
applyChangeTracking(doc, p);
|
|
84
|
+
}
|
|
85
|
+
} else if (included) {
|
|
86
|
+
// selected field
|
|
87
|
+
try {
|
|
88
|
+
def = type.getDefault(doc, false);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
doc.invalidate(p, err);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (typeof def !== 'undefined') {
|
|
95
|
+
doc_[piece] = def;
|
|
96
|
+
applyChangeTracking(doc, p);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
try {
|
|
101
|
+
def = type.getDefault(doc, false);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
doc.invalidate(p, err);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof def !== 'undefined') {
|
|
108
|
+
doc_[piece] = def;
|
|
109
|
+
applyChangeTracking(doc, p);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
doc_ = doc_[piece];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/*!
|
|
120
|
+
* ignore
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
function applyChangeTracking(doc, fullPath) {
|
|
124
|
+
doc.$__.activePaths.default(fullPath);
|
|
125
|
+
if (doc.$isSubdocument && doc.$isSingleNested && doc.$parent() != null) {
|
|
126
|
+
doc.$parent().$__.activePaths.default(doc.$__pathRelativeToParent(fullPath));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* ignore
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
module.exports = function cleanModifiedSubpaths(doc, path, options) {
|
|
8
|
+
options = options || {};
|
|
9
|
+
const skipDocArrays = options.skipDocArrays;
|
|
10
|
+
|
|
11
|
+
let deleted = 0;
|
|
12
|
+
if (!doc) {
|
|
13
|
+
return deleted;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (const modifiedPath of Object.keys(doc.$__.activePaths.getStatePaths('modify'))) {
|
|
17
|
+
if (skipDocArrays) {
|
|
18
|
+
const schemaType = doc.$__schema.path(modifiedPath);
|
|
19
|
+
if (schemaType && schemaType.$isMongooseDocumentArray) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (modifiedPath.startsWith(path + '.')) {
|
|
24
|
+
doc.$__.activePaths.clearPath(modifiedPath);
|
|
25
|
+
++deleted;
|
|
26
|
+
|
|
27
|
+
if (doc.$isSubdocument) {
|
|
28
|
+
const owner = doc.ownerDocument();
|
|
29
|
+
const fullPath = doc.$__fullPath(modifiedPath);
|
|
30
|
+
owner.$__.activePaths.clearPath(fullPath);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return deleted;
|
|
35
|
+
};
|