@nullix/zod-mongoose-studio 1.0.13 → 2.1.0
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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/8b851c04-1848-472a-b5cd-0727aaaf90f4.json +1 -0
- package/.output/server/chunks/nitro/nitro.mjs +232 -232
- package/.output/server/chunks/routes/api/parse.post.mjs +54 -11
- package/.output/server/chunks/routes/api/parse.post.mjs.map +1 -1
- package/.output/server/node_modules/bson/lib/bson.cjs +157 -48
- package/.output/server/node_modules/bson/package.json +9 -11
- package/.output/server/node_modules/kareem/index.js +228 -343
- package/.output/server/node_modules/kareem/package.json +3 -3
- package/.output/server/node_modules/mongodb/lib/bson.js +27 -5
- package/.output/server/node_modules/mongodb/lib/bulk/common.js +7 -9
- package/.output/server/node_modules/mongodb/lib/change_stream.js +91 -39
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js +21 -14
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/client_encryption.js +2 -5
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/errors.js +3 -1
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js +1 -1
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/state_machine.js +1 -0
- package/.output/server/node_modules/mongodb/lib/cmap/auth/aws4.js +161 -0
- package/.output/server/node_modules/mongodb/lib/cmap/auth/aws_temporary_credentials.js +11 -58
- package/.output/server/node_modules/mongodb/lib/cmap/auth/gssapi.js +4 -6
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongo_credentials.js +2 -16
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js +14 -23
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +4 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +4 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js +4 -4
- package/.output/server/node_modules/mongodb/lib/cmap/auth/plain.js +1 -1
- package/.output/server/node_modules/mongodb/lib/cmap/auth/providers.js +0 -1
- package/.output/server/node_modules/mongodb/lib/cmap/auth/scram.js +53 -40
- package/.output/server/node_modules/mongodb/lib/cmap/commands.js +46 -39
- package/.output/server/node_modules/mongodb/lib/cmap/connect.js +35 -3
- package/.output/server/node_modules/mongodb/lib/cmap/connection.js +36 -32
- package/.output/server/node_modules/mongodb/lib/cmap/connection_pool.js +67 -67
- package/.output/server/node_modules/mongodb/lib/cmap/connection_pool_events.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/errors.js +1 -1
- package/.output/server/node_modules/mongodb/lib/cmap/handshake/client_metadata.js +15 -13
- package/.output/server/node_modules/mongodb/lib/cmap/metrics.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/compression.js +26 -10
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/constants.js +3 -1
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_data.js +0 -1
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_demand/document.js +9 -9
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/responses.js +2 -2
- package/.output/server/node_modules/mongodb/lib/collection.js +1 -1
- package/.output/server/node_modules/mongodb/lib/connection_string.js +30 -15
- package/.output/server/node_modules/mongodb/lib/cursor/abstract_cursor.js +17 -34
- package/.output/server/node_modules/mongodb/lib/cursor/change_stream_cursor.js +2 -2
- package/.output/server/node_modules/mongodb/lib/cursor/find_cursor.js +37 -26
- package/.output/server/node_modules/mongodb/lib/cursor/run_command_cursor.js +1 -1
- package/.output/server/node_modules/mongodb/lib/db.js +6 -7
- package/.output/server/node_modules/mongodb/lib/deps.js +0 -13
- package/.output/server/node_modules/mongodb/lib/error.js +7 -10
- package/.output/server/node_modules/mongodb/lib/gridfs/download.js +7 -6
- package/.output/server/node_modules/mongodb/lib/gridfs/index.js +9 -9
- package/.output/server/node_modules/mongodb/lib/gridfs/upload.js +17 -23
- package/.output/server/node_modules/mongodb/lib/index.js +2 -4
- package/.output/server/node_modules/mongodb/lib/mongo_client.js +58 -67
- package/.output/server/node_modules/mongodb/lib/mongo_client_auth_providers.js +0 -6
- package/.output/server/node_modules/mongodb/lib/mongo_logger.js +11 -5
- package/.output/server/node_modules/mongodb/lib/mongo_types.js +1 -2
- package/.output/server/node_modules/mongodb/lib/operations/aggregate.js +0 -3
- package/.output/server/node_modules/mongodb/lib/operations/create_collection.js +0 -1
- package/.output/server/node_modules/mongodb/lib/operations/drop.js +8 -9
- package/.output/server/node_modules/mongodb/lib/operations/end_sessions.js +34 -0
- package/.output/server/node_modules/mongodb/lib/operations/execute_operation.js +121 -45
- package/.output/server/node_modules/mongodb/lib/operations/operation.js +1 -0
- package/.output/server/node_modules/mongodb/lib/read_preference.js +10 -14
- package/.output/server/node_modules/mongodb/lib/runtime_adapters.js +32 -0
- package/.output/server/node_modules/mongodb/lib/sdam/monitor.js +8 -8
- package/.output/server/node_modules/mongodb/lib/sdam/server.js +55 -43
- package/.output/server/node_modules/mongodb/lib/sdam/server_description.js +1 -1
- package/.output/server/node_modules/mongodb/lib/sdam/server_selection.js +135 -72
- package/.output/server/node_modules/mongodb/lib/sdam/srv_polling.js +3 -3
- package/.output/server/node_modules/mongodb/lib/sdam/topology.js +37 -77
- package/.output/server/node_modules/mongodb/lib/sdam/topology_description.js +1 -1
- package/.output/server/node_modules/mongodb/lib/sessions.js +150 -40
- package/.output/server/node_modules/mongodb/lib/transactions.js +2 -13
- package/.output/server/node_modules/mongodb/lib/utils.js +42 -90
- package/.output/server/node_modules/mongodb/package.json +49 -45
- package/.output/server/node_modules/mongodb-connection-string-url/lib/index.js +45 -19
- package/.output/server/node_modules/mongodb-connection-string-url/lib/redact.js +30 -19
- package/.output/server/node_modules/mongodb-connection-string-url/package.json +25 -16
- package/.output/server/node_modules/mongoose/lib/aggregate.js +108 -127
- package/.output/server/node_modules/mongoose/lib/cast/bigint.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/boolean.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/double.js +4 -4
- package/.output/server/node_modules/mongoose/lib/cast/int32.js +2 -2
- package/.output/server/node_modules/mongoose/lib/cast/number.js +6 -6
- package/.output/server/node_modules/mongoose/lib/cast/string.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/uuid.js +5 -48
- package/.output/server/node_modules/mongoose/lib/cast.js +16 -24
- package/.output/server/node_modules/mongoose/lib/collection.js +6 -6
- package/.output/server/node_modules/mongoose/lib/connection.js +108 -105
- package/.output/server/node_modules/mongoose/lib/cursor/aggregationCursor.js +23 -33
- package/.output/server/node_modules/mongoose/lib/cursor/changeStream.js +60 -40
- package/.output/server/node_modules/mongoose/lib/cursor/queryCursor.js +21 -25
- package/.output/server/node_modules/mongoose/lib/document.js +712 -531
- package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +85 -130
- package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +32 -41
- package/.output/server/node_modules/mongoose/lib/error/cast.js +21 -12
- package/.output/server/node_modules/mongoose/lib/error/createCollectionsError.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/divergentArray.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/eachAsyncMultiError.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/index.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/invalidSchemaOption.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/messages.js +1 -0
- package/.output/server/node_modules/mongoose/lib/error/missingSchema.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/objectParameter.js +4 -5
- package/.output/server/node_modules/mongoose/lib/error/overwriteModel.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/setOptionError.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/strict.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/strictPopulate.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/syncIndexes.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/validation.js +2 -10
- package/.output/server/node_modules/mongoose/lib/error/validator.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/version.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/buildMiddlewareFilter.js +24 -0
- package/.output/server/node_modules/mongoose/lib/helpers/clone.js +35 -18
- package/.output/server/node_modules/mongoose/lib/helpers/common.js +5 -5
- package/.output/server/node_modules/mongoose/lib/helpers/cursor/eachAsync.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getConstructor.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js +10 -5
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyDefaults.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyTimestamps.js +11 -10
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyVirtuals.js +10 -9
- package/.output/server/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/document/compile.js +17 -14
- package/.output/server/node_modules/mongoose/lib/helpers/document/getDeepestSubdocumentForPath.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/document/isInPathsToSave.js +24 -0
- package/.output/server/node_modules/mongoose/lib/helpers/get.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/getRelatedIndexes.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexEqual.js +3 -4
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/isBsonType.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/isMongooseObject.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/isObject.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/isSimpleValidator.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/minimize.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyHooks.js +55 -54
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyMethods.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyStaticHooks.js +1 -48
- package/.output/server/node_modules/mongoose/lib/helpers/model/castBulkWrite.js +8 -12
- package/.output/server/node_modules/mongoose/lib/helpers/model/discriminator.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/parallelLimit.js +18 -36
- package/.output/server/node_modules/mongoose/lib/helpers/pluralize.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -11
- package/.output/server/node_modules/mongoose/lib/helpers/populate/assignVals.js +10 -10
- package/.output/server/node_modules/mongoose/lib/helpers/populate/createPopulateQueryFilter.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js +197 -69
- package/.output/server/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js +15 -15
- package/.output/server/node_modules/mongoose/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/populate/modelNamesFromRefPath.js +10 -2
- package/.output/server/node_modules/mongoose/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/.output/server/node_modules/mongoose/lib/helpers/printJestWarning.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/processConnectionOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/projection/isSubpath.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/parseProjection.js +9 -4
- package/.output/server/node_modules/mongoose/lib/helpers/query/cast$expr.js +8 -10
- package/.output/server/node_modules/mongoose/lib/helpers/query/castFilterPath.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/query/castUpdate.js +44 -38
- package/.output/server/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js +8 -8
- package/.output/server/node_modules/mongoose/lib/helpers/query/handleImmutable.js +8 -8
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyPlugins.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyReadConcern.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyWriteConcern.js +4 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/getIndexes.js +5 -11
- package/.output/server/node_modules/mongoose/lib/helpers/schema/getSubdocumentStrictValue.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/handleIdOption.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schema/idGetter.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schematype/handleImmutable.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js +26 -13
- package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js +60 -38
- package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToUpdate.js +13 -10
- package/.output/server/node_modules/mongoose/lib/helpers/update/castArrayFilters.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/update/modifiedPaths.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
- package/.output/server/node_modules/mongoose/lib/helpers/updateValidators.js +58 -119
- package/.output/server/node_modules/mongoose/lib/model.js +940 -946
- package/.output/server/node_modules/mongoose/lib/mongoose.js +131 -79
- package/.output/server/node_modules/mongoose/lib/options/schemaArrayOptions.js +2 -2
- package/.output/server/node_modules/mongoose/lib/options/schemaBufferOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/options/schemaDocumentArrayOptions.js +23 -0
- package/.output/server/node_modules/mongoose/lib/options/schemaNumberOptions.js +3 -3
- package/.output/server/node_modules/mongoose/lib/options/schemaObjectIdOptions.js +2 -2
- package/.output/server/node_modules/mongoose/lib/options/schemaStringOptions.js +6 -6
- package/.output/server/node_modules/mongoose/lib/options/schemaSubdocumentOptions.js +23 -0
- package/.output/server/node_modules/mongoose/lib/options/schemaTypeOptions.js +27 -13
- package/.output/server/node_modules/mongoose/lib/options/virtualOptions.js +12 -12
- package/.output/server/node_modules/mongoose/lib/plugins/index.js +0 -1
- package/.output/server/node_modules/mongoose/lib/plugins/saveSubdocs.js +84 -92
- package/.output/server/node_modules/mongoose/lib/plugins/sharding.js +33 -15
- package/.output/server/node_modules/mongoose/lib/plugins/trackTransaction.js +29 -25
- package/.output/server/node_modules/mongoose/lib/query.js +700 -548
- package/.output/server/node_modules/mongoose/lib/queryHelpers.js +34 -32
- package/.output/server/node_modules/mongoose/lib/schema/array.js +69 -113
- package/.output/server/node_modules/mongoose/lib/schema/bigint.js +18 -20
- package/.output/server/node_modules/mongoose/lib/schema/boolean.js +20 -22
- package/.output/server/node_modules/mongoose/lib/schema/buffer.js +23 -25
- package/.output/server/node_modules/mongoose/lib/schema/date.js +19 -21
- package/.output/server/node_modules/mongoose/lib/schema/decimal128.js +16 -18
- package/.output/server/node_modules/mongoose/lib/schema/documentArray.js +94 -131
- package/.output/server/node_modules/mongoose/lib/schema/documentArrayElement.js +50 -16
- package/.output/server/node_modules/mongoose/lib/schema/double.js +16 -18
- package/.output/server/node_modules/mongoose/lib/schema/index.js +1 -0
- package/.output/server/node_modules/mongoose/lib/schema/int32.js +17 -19
- package/.output/server/node_modules/mongoose/lib/schema/map.js +17 -24
- package/.output/server/node_modules/mongoose/lib/schema/mixed.js +14 -14
- package/.output/server/node_modules/mongoose/lib/schema/number.js +38 -28
- package/.output/server/node_modules/mongoose/lib/schema/objectId.js +18 -20
- package/.output/server/node_modules/mongoose/lib/schema/operators/exists.js +1 -1
- package/.output/server/node_modules/mongoose/lib/schema/operators/geospatial.js +1 -1
- package/.output/server/node_modules/mongoose/lib/schema/operators/text.js +4 -4
- package/.output/server/node_modules/mongoose/lib/schema/string.js +42 -27
- package/.output/server/node_modules/mongoose/lib/schema/subdocument.js +47 -58
- package/.output/server/node_modules/mongoose/lib/schema/union.js +54 -4
- package/.output/server/node_modules/mongoose/lib/schema/uuid.js +17 -40
- package/.output/server/node_modules/mongoose/lib/schema.js +235 -176
- package/.output/server/node_modules/mongoose/lib/schemaType.js +227 -158
- package/.output/server/node_modules/mongoose/lib/stateMachine.js +5 -8
- package/.output/server/node_modules/mongoose/lib/types/array/index.js +5 -5
- package/.output/server/node_modules/mongoose/lib/types/array/methods/index.js +27 -28
- package/.output/server/node_modules/mongoose/lib/types/arraySubdocument.js +11 -11
- package/.output/server/node_modules/mongoose/lib/types/buffer.js +15 -15
- package/.output/server/node_modules/mongoose/lib/types/decimal128.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/documentArray/index.js +4 -4
- package/.output/server/node_modules/mongoose/lib/types/documentArray/methods/index.js +15 -13
- package/.output/server/node_modules/mongoose/lib/types/double.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/map.js +20 -71
- package/.output/server/node_modules/mongoose/lib/types/objectid.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/subdocument.js +32 -81
- package/.output/server/node_modules/mongoose/lib/types/uuid.js +1 -1
- package/.output/server/node_modules/mongoose/lib/utils.js +91 -70
- package/.output/server/node_modules/mongoose/lib/validOptions.js +4 -3
- package/.output/server/node_modules/mongoose/lib/virtualType.js +18 -18
- package/.output/server/node_modules/mongoose/package.json +46 -63
- package/.output/server/node_modules/mquery/lib/collection/collection.js +3 -1
- package/.output/server/node_modules/mquery/lib/collection/node.js +17 -3
- package/.output/server/node_modules/mquery/lib/mquery.js +136 -93
- package/.output/server/node_modules/mquery/lib/permissions.js +21 -6
- package/.output/server/node_modules/mquery/package.json +4 -7
- package/.output/server/package.json +7 -9
- package/package.json +3 -3
- package/.output/public/_nuxt/builds/meta/0d6006db-fbb0-4297-85cf-bf92ceafcb79.json +0 -1
- package/.output/server/node_modules/debug/package.json +0 -64
- package/.output/server/node_modules/debug/src/browser.js +0 -272
- package/.output/server/node_modules/debug/src/common.js +0 -292
- package/.output/server/node_modules/debug/src/index.js +0 -10
- package/.output/server/node_modules/debug/src/node.js +0 -263
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/crypto_callbacks.js +0 -81
- package/.output/server/node_modules/mongodb/lib/resource_management.js +0 -58
- package/.output/server/node_modules/mongoose/lib/browserDocument.js +0 -101
- package/.output/server/node_modules/mongoose/lib/documentProvider.js +0 -30
- package/.output/server/node_modules/mongoose/lib/helpers/createJSONSchemaTypeDefinition.js +0 -24
- package/.output/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js +0 -54
- package/.output/server/node_modules/mongoose/lib/plugins/validateBeforeSave.js +0 -51
- package/.output/server/node_modules/supports-color/index.js +0 -202
- package/.output/server/node_modules/supports-color/package.json +0 -64
|
@@ -132,7 +132,7 @@ Object.defineProperty(Connection.prototype, 'readyState', {
|
|
|
132
132
|
},
|
|
133
133
|
set: function(val) {
|
|
134
134
|
if (!(val in STATES)) {
|
|
135
|
-
throw new
|
|
135
|
+
throw new MongooseError('Invalid connection state: ' + val);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
if (this._readyState !== val) {
|
|
@@ -158,7 +158,7 @@ Object.defineProperty(Connection.prototype, 'readyState', {
|
|
|
158
158
|
*
|
|
159
159
|
* conn.get('test'); // returns the 'test' value
|
|
160
160
|
*
|
|
161
|
-
* @param {
|
|
161
|
+
* @param {string} key
|
|
162
162
|
* @method get
|
|
163
163
|
* @api public
|
|
164
164
|
*/
|
|
@@ -177,7 +177,7 @@ Connection.prototype.get = function getOption(key) {
|
|
|
177
177
|
* Supported options include:
|
|
178
178
|
*
|
|
179
179
|
* - `maxTimeMS`: Set [`maxTimeMS`](https://mongoosejs.com/docs/api/query.html#Query.prototype.maxTimeMS()) for all queries on this connection.
|
|
180
|
-
* - 'debug': If `true`, prints the operations mongoose sends to MongoDB to the console. If a writable stream is passed, it will log to that stream, without colorization. If a callback function is passed, it will receive the collection name, the method name, then all
|
|
180
|
+
* - 'debug': If `true`, prints the operations mongoose sends to MongoDB to the console. If a writable stream is passed, it will log to that stream, without colorization. If a callback function is passed, it will receive the collection name, the method name, then all arguments passed to the method. For example, if you wanted to replicate the default logging, you could output from the callback `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
|
|
181
181
|
*
|
|
182
182
|
* #### Example:
|
|
183
183
|
*
|
|
@@ -185,8 +185,8 @@ Connection.prototype.get = function getOption(key) {
|
|
|
185
185
|
* conn.get('test'); // 'foo'
|
|
186
186
|
* conn.options.test; // 'foo'
|
|
187
187
|
*
|
|
188
|
-
* @param {
|
|
189
|
-
* @param {
|
|
188
|
+
* @param {string} key
|
|
189
|
+
* @param {any} val
|
|
190
190
|
* @method set
|
|
191
191
|
* @api public
|
|
192
192
|
*/
|
|
@@ -410,11 +410,11 @@ Connection.prototype.config;
|
|
|
410
410
|
* with specified options. Used to create [capped collections](https://www.mongodb.com/docs/manual/core/capped-collections/)
|
|
411
411
|
* and [views](https://www.mongodb.com/docs/manual/core/views/) from mongoose.
|
|
412
412
|
*
|
|
413
|
-
* Options are passed down without modification to the [MongoDB driver's `createCollection()` function](https://mongodb.github.io/node-mongodb-native/
|
|
413
|
+
* Options are passed down without modification to the [MongoDB driver's `createCollection()` function](https://mongodb.github.io/node-mongodb-native/7.0/classes/Db.html#createCollection)
|
|
414
414
|
*
|
|
415
415
|
* @method createCollection
|
|
416
416
|
* @param {string} collection The collection to create
|
|
417
|
-
* @param {
|
|
417
|
+
* @param {object} [options] see [MongoDB driver docs](https://mongodb.github.io/node-mongodb-native/7.0/classes/Db.html#createCollection)
|
|
418
418
|
* @return {Promise}
|
|
419
419
|
* @api public
|
|
420
420
|
*/
|
|
@@ -444,8 +444,8 @@ Connection.prototype.createCollection = async function createCollection(collecti
|
|
|
444
444
|
*
|
|
445
445
|
* @method bulkWrite
|
|
446
446
|
* @param {Array} ops
|
|
447
|
-
* @param {
|
|
448
|
-
* @param {
|
|
447
|
+
* @param {object} [options]
|
|
448
|
+
* @param {boolean} [options.ordered] If false, perform unordered operations. If true, perform ordered operations.
|
|
449
449
|
* @param {Session} [options.session] The session to use for the operation.
|
|
450
450
|
* @return {Promise}
|
|
451
451
|
* @see MongoDB https://www.mongodb.com/docs/manual/reference/command/bulkWrite/#mongodb-dbcommand-dbcmd.bulkWrite
|
|
@@ -606,7 +606,7 @@ Connection.prototype.bulkWrite = async function bulkWrite(ops, options) {
|
|
|
606
606
|
* Calls `createCollection()` on a models in a series.
|
|
607
607
|
*
|
|
608
608
|
* @method createCollections
|
|
609
|
-
* @param {
|
|
609
|
+
* @param {boolean} continueOnError When true, will continue to create collections and create a new error class for the collections that errored.
|
|
610
610
|
* @returns {Promise}
|
|
611
611
|
* @api public
|
|
612
612
|
*/
|
|
@@ -630,7 +630,7 @@ Connection.prototype.createCollections = async function createCollections(option
|
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
632
|
|
|
633
|
-
if (!continueOnError &&
|
|
633
|
+
if (!continueOnError && utils.hasOwnKeys(errorsMap)) {
|
|
634
634
|
const message = Object.entries(errorsMap).map(([modelName, err]) => `${modelName}: ${err.message}`).join(', ');
|
|
635
635
|
const createCollectionsError = new CreateCollectionsError(message, errorsMap);
|
|
636
636
|
throw createCollectionsError;
|
|
@@ -655,7 +655,7 @@ Connection.prototype.createCollections = async function createCollections(option
|
|
|
655
655
|
|
|
656
656
|
Connection.prototype.withSession = async function withSession(executor) {
|
|
657
657
|
if (arguments.length === 0) {
|
|
658
|
-
throw new
|
|
658
|
+
throw new MongooseError('Please provide an executor function');
|
|
659
659
|
}
|
|
660
660
|
return await this.client.withSession(executor);
|
|
661
661
|
};
|
|
@@ -678,8 +678,8 @@ Connection.prototype.withSession = async function withSession(executor) {
|
|
|
678
678
|
*
|
|
679
679
|
*
|
|
680
680
|
* @method startSession
|
|
681
|
-
* @param {
|
|
682
|
-
* @param {
|
|
681
|
+
* @param {object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/7.0/classes/MongoClient.html#startSession)
|
|
682
|
+
* @param {boolean} [options.causalConsistency=true] set to false to disable causal consistency
|
|
683
683
|
* @return {Promise<ClientSession>} promise that resolves to a MongoDB driver `ClientSession`
|
|
684
684
|
* @api public
|
|
685
685
|
*/
|
|
@@ -701,7 +701,7 @@ Connection.prototype.startSession = async function startSession(options) {
|
|
|
701
701
|
* async function executes successfully and attempt to retry if
|
|
702
702
|
* there was a retriable error.
|
|
703
703
|
*
|
|
704
|
-
* Calls the MongoDB driver's [`session.withTransaction()`](https://mongodb.github.io/node-mongodb-native/
|
|
704
|
+
* Calls the MongoDB driver's [`session.withTransaction()`](https://mongodb.github.io/node-mongodb-native/7.0/classes/ClientSession.html#withTransaction),
|
|
705
705
|
* but also handles resetting Mongoose document state as shown below.
|
|
706
706
|
*
|
|
707
707
|
* #### Example:
|
|
@@ -713,7 +713,7 @@ Connection.prototype.startSession = async function startSession(options) {
|
|
|
713
713
|
* doc.isNew; // false
|
|
714
714
|
*
|
|
715
715
|
* // Throw an error to abort the transaction
|
|
716
|
-
* throw new
|
|
716
|
+
* throw new MongooseError('Oops!');
|
|
717
717
|
* },{ readPreference: 'primary' }).catch(() => {});
|
|
718
718
|
*
|
|
719
719
|
* // true, `transaction()` reset the document's state because the
|
|
@@ -723,7 +723,7 @@ Connection.prototype.startSession = async function startSession(options) {
|
|
|
723
723
|
* @method transaction
|
|
724
724
|
* @param {Function} fn Function to execute in a transaction
|
|
725
725
|
* @param {mongodb.TransactionOptions} [options] Optional settings for the transaction
|
|
726
|
-
* @return {Promise<
|
|
726
|
+
* @return {Promise<any>} promise that is fulfilled if Mongoose successfully committed the transaction, or rejects if the transaction was aborted or if Mongoose failed to commit the transaction. If fulfilled, the promise resolves to a MongoDB command result.
|
|
727
727
|
* @api public
|
|
728
728
|
*/
|
|
729
729
|
|
|
@@ -824,8 +824,8 @@ Connection.prototype.dropCollection = async function dropCollection(collection)
|
|
|
824
824
|
/**
|
|
825
825
|
* Waits for connection to be established, so the connection has a `client`
|
|
826
826
|
*
|
|
827
|
-
* @param {
|
|
828
|
-
* @return Promise
|
|
827
|
+
* @param {boolean} [noTimeout=false] if set, don't put a timeout on the operation. Used internally so `mongoose.model()` doesn't leave open handles.
|
|
828
|
+
* @return {Promise}
|
|
829
829
|
* @api private
|
|
830
830
|
*/
|
|
831
831
|
|
|
@@ -883,7 +883,7 @@ Connection.prototype._getBufferTimeoutMS = function _getBufferTimeoutMS() {
|
|
|
883
883
|
if (this.config.bufferTimeoutMS != null) {
|
|
884
884
|
return this.config.bufferTimeoutMS;
|
|
885
885
|
}
|
|
886
|
-
if (this.base
|
|
886
|
+
if (this.base?.get('bufferTimeoutMS') != null) {
|
|
887
887
|
return this.base.get('bufferTimeoutMS');
|
|
888
888
|
}
|
|
889
889
|
return 10000;
|
|
@@ -894,7 +894,7 @@ Connection.prototype._getBufferTimeoutMS = function _getBufferTimeoutMS() {
|
|
|
894
894
|
* Returns an array of collection objects.
|
|
895
895
|
*
|
|
896
896
|
* @method listCollections
|
|
897
|
-
* @return {Promise<Collection
|
|
897
|
+
* @return {Promise<Array<Collection>>}
|
|
898
898
|
* @api public
|
|
899
899
|
*/
|
|
900
900
|
|
|
@@ -915,7 +915,7 @@ Connection.prototype.listCollections = async function listCollections() {
|
|
|
915
915
|
* databases; // [{ name: 'mongoose_test', sizeOnDisk: 0, empty: false }]
|
|
916
916
|
*
|
|
917
917
|
* @method listCollections
|
|
918
|
-
* @return {Promise<{ databases:
|
|
918
|
+
* @return {Promise<Array<{ databases: { name: string } }>>}
|
|
919
919
|
* @api public
|
|
920
920
|
*/
|
|
921
921
|
|
|
@@ -1005,10 +1005,7 @@ Connection.prototype.error = function error(err, callback) {
|
|
|
1005
1005
|
Connection.prototype.onOpen = function() {
|
|
1006
1006
|
this.readyState = STATES.connected;
|
|
1007
1007
|
|
|
1008
|
-
|
|
1009
|
-
d.fn.apply(d.ctx, d.args);
|
|
1010
|
-
}
|
|
1011
|
-
this._queue = [];
|
|
1008
|
+
this._flushQueue();
|
|
1012
1009
|
|
|
1013
1010
|
// avoid having the collection subscribe to our event emitter
|
|
1014
1011
|
// to prevent 0.3 warning
|
|
@@ -1021,25 +1018,39 @@ Connection.prototype.onOpen = function() {
|
|
|
1021
1018
|
this.emit('open');
|
|
1022
1019
|
};
|
|
1023
1020
|
|
|
1021
|
+
/**
|
|
1022
|
+
* Flush all buffered operations in `_queue`. Called by `onOpen()` and
|
|
1023
|
+
* by the heartbeat handler when a previously-stale connection recovers.
|
|
1024
|
+
*
|
|
1025
|
+
* @api private
|
|
1026
|
+
*/
|
|
1027
|
+
|
|
1028
|
+
Connection.prototype._flushQueue = function _flushQueue() {
|
|
1029
|
+
const queue = this._queue;
|
|
1030
|
+
this._queue = [];
|
|
1031
|
+
for (const d of queue) {
|
|
1032
|
+
d.fn.apply(d.ctx, d.args);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1024
1036
|
/**
|
|
1025
1037
|
* Opens the connection with a URI using `MongoClient.connect()`.
|
|
1026
1038
|
*
|
|
1027
|
-
* @param {
|
|
1028
|
-
* @param {
|
|
1029
|
-
* @param {
|
|
1030
|
-
* @param {
|
|
1031
|
-
* @param {
|
|
1032
|
-
* @param {
|
|
1033
|
-
* @param {
|
|
1034
|
-
* @param {
|
|
1035
|
-
* @param {
|
|
1036
|
-
* @param {
|
|
1037
|
-
* @param {
|
|
1038
|
-
* @param {
|
|
1039
|
-
* @param {
|
|
1040
|
-
* @param {
|
|
1041
|
-
* @param {
|
|
1042
|
-
* @param {Boolean} [options.autoCreate=false] Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection.
|
|
1039
|
+
* @param {string} uri The URI to connect with.
|
|
1040
|
+
* @param {object} [options] Passed on to [`MongoClient.connect`](https://mongodb.github.io/node-mongodb-native/7.0/classes/MongoClient.html#connect)
|
|
1041
|
+
* @param {boolean} [options.bufferCommands=true] Mongoose specific option. Set to false to [disable buffering](https://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection.
|
|
1042
|
+
* @param {number} [options.bufferTimeoutMS=10000] Mongoose specific option. If `bufferCommands` is true, Mongoose will throw an error after `bufferTimeoutMS` if the operation is still buffered.
|
|
1043
|
+
* @param {string} [options.dbName] The name of the database we want to use. If not provided, use database name from connection string.
|
|
1044
|
+
* @param {string} [options.user] username for authentication, equivalent to `options.auth.username`. Maintained for backwards compatibility.
|
|
1045
|
+
* @param {string} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility.
|
|
1046
|
+
* @param {number} [options.maxPoolSize=100] The maximum number of sockets the MongoDB driver will keep open for this connection. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs).
|
|
1047
|
+
* @param {number} [options.minPoolSize=0] The minimum number of sockets the MongoDB driver will keep open for this connection. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs).
|
|
1048
|
+
* @param {number} [options.serverSelectionTimeoutMS] The MongoDB driver will try to find a server to send any given operation to, and keep retrying for `serverSelectionTimeoutMS` milliseconds before erroring out. If not set, the MongoDB driver defaults to using `30000` (30 seconds).
|
|
1049
|
+
* @param {number} [options.heartbeatFrequencyMS] The MongoDB driver sends a heartbeat every `heartbeatFrequencyMS` to check on the status of the connection. A heartbeat is subject to `serverSelectionTimeoutMS`, so the MongoDB driver will retry failed heartbeats for up to 30 seconds by default. Mongoose only emits a `'disconnected'` event after a heartbeat has failed, so you may want to decrease this setting to reduce the time between when your server goes down and when Mongoose emits `'disconnected'`. We recommend you do **not** set this setting below 1000, too many heartbeats can lead to performance degradation.
|
|
1050
|
+
* @param {boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
|
|
1051
|
+
* @param {number} [options.socketTimeoutMS=0] How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. `socketTimeoutMS` defaults to 0, which means Node.js will not time out the socket due to inactivity. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.
|
|
1052
|
+
* @param {number} [options.family=0] Passed transparently to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. May be either `0`, `4`, or `6`. `4` means use IPv4 only, `6` means use IPv6 only, `0` means try both.
|
|
1053
|
+
* @param {boolean} [options.autoCreate=false] Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection.
|
|
1043
1054
|
* @returns {Promise<Connection>}
|
|
1044
1055
|
* @api public
|
|
1045
1056
|
*/
|
|
@@ -1106,7 +1117,7 @@ Connection.prototype.openUri = async function openUri(uri, options) {
|
|
|
1106
1117
|
/**
|
|
1107
1118
|
* Listen to events in the Connection
|
|
1108
1119
|
*
|
|
1109
|
-
* @param {
|
|
1120
|
+
* @param {string} event The event to listen on
|
|
1110
1121
|
* @param {Function} callback
|
|
1111
1122
|
* @see Connection#readyState https://mongoosejs.com/docs/api/connection.html#Connection.prototype.readyState
|
|
1112
1123
|
*
|
|
@@ -1128,7 +1139,7 @@ Connection.prototype.on = function on(event, callback) {
|
|
|
1128
1139
|
/**
|
|
1129
1140
|
* Listen to a event once in the Connection
|
|
1130
1141
|
*
|
|
1131
|
-
* @param {
|
|
1142
|
+
* @param {string} event The event to listen on
|
|
1132
1143
|
* @param {Function} callback
|
|
1133
1144
|
* @see Connection#readyState https://mongoosejs.com/docs/api/connection.html#Connection.prototype.readyState
|
|
1134
1145
|
*
|
|
@@ -1178,7 +1189,7 @@ function _handleConnectionErrors(err) {
|
|
|
1178
1189
|
* but also removes the connection from Mongoose's `connections` list and prevents the
|
|
1179
1190
|
* connection from ever being re-opened.
|
|
1180
1191
|
*
|
|
1181
|
-
* @param {
|
|
1192
|
+
* @param {boolean} [force]
|
|
1182
1193
|
* @returns {Promise}
|
|
1183
1194
|
*/
|
|
1184
1195
|
|
|
@@ -1199,7 +1210,7 @@ Connection.prototype.destroy = async function destroy(force) {
|
|
|
1199
1210
|
/**
|
|
1200
1211
|
* Closes the connection
|
|
1201
1212
|
*
|
|
1202
|
-
* @param {
|
|
1213
|
+
* @param {boolean} [force] optional
|
|
1203
1214
|
* @return {Promise}
|
|
1204
1215
|
* @api public
|
|
1205
1216
|
*/
|
|
@@ -1232,8 +1243,8 @@ Connection.prototype.close = async function close(force) {
|
|
|
1232
1243
|
/**
|
|
1233
1244
|
* Handles closing the connection
|
|
1234
1245
|
*
|
|
1235
|
-
* @param {
|
|
1236
|
-
* @param {
|
|
1246
|
+
* @param {boolean} force
|
|
1247
|
+
* @param {boolean} destroy
|
|
1237
1248
|
* @returns {Connection} this
|
|
1238
1249
|
* @api private
|
|
1239
1250
|
*/
|
|
@@ -1250,8 +1261,11 @@ Connection.prototype._close = async function _close(force, destroy) {
|
|
|
1250
1261
|
const conn = this;
|
|
1251
1262
|
switch (this.readyState) {
|
|
1252
1263
|
case STATES.disconnected:
|
|
1253
|
-
if (destroy
|
|
1254
|
-
this.base.connections.
|
|
1264
|
+
if (destroy) {
|
|
1265
|
+
const index = this.base.connections.indexOf(conn);
|
|
1266
|
+
if (index !== -1) {
|
|
1267
|
+
this.base.connections.splice(index, 1);
|
|
1268
|
+
}
|
|
1255
1269
|
}
|
|
1256
1270
|
if (!closeCalled) {
|
|
1257
1271
|
await this.doClose(force);
|
|
@@ -1262,8 +1276,11 @@ Connection.prototype._close = async function _close(force, destroy) {
|
|
|
1262
1276
|
case STATES.connected:
|
|
1263
1277
|
this.readyState = STATES.disconnecting;
|
|
1264
1278
|
await this.doClose(force);
|
|
1265
|
-
if (destroy
|
|
1266
|
-
|
|
1279
|
+
if (destroy) {
|
|
1280
|
+
const index = _this.base.connections.indexOf(conn);
|
|
1281
|
+
if (index !== -1) {
|
|
1282
|
+
this.base.connections.splice(index, 1);
|
|
1283
|
+
}
|
|
1267
1284
|
}
|
|
1268
1285
|
this.onClose(force);
|
|
1269
1286
|
|
|
@@ -1305,7 +1322,7 @@ Connection.prototype._close = async function _close(force, destroy) {
|
|
|
1305
1322
|
*/
|
|
1306
1323
|
|
|
1307
1324
|
Connection.prototype.doClose = function doClose() {
|
|
1308
|
-
throw new
|
|
1325
|
+
throw new MongooseError('Connection#doClose unimplemented by driver');
|
|
1309
1326
|
};
|
|
1310
1327
|
|
|
1311
1328
|
/**
|
|
@@ -1341,21 +1358,21 @@ Connection.prototype.onClose = function onClose(force) {
|
|
|
1341
1358
|
* Using a Collection bypasses Mongoose middleware, validation, and casting,
|
|
1342
1359
|
* letting you use [MongoDB Node.js driver](https://mongodb.github.io/node-mongodb-native/) functionality directly.
|
|
1343
1360
|
*
|
|
1344
|
-
* @param {
|
|
1345
|
-
* @param {
|
|
1361
|
+
* @param {string} name of the collection
|
|
1362
|
+
* @param {object} [options] optional collection options
|
|
1346
1363
|
* @return {Collection} collection instance
|
|
1347
1364
|
* @api public
|
|
1348
1365
|
*/
|
|
1349
1366
|
|
|
1350
1367
|
Connection.prototype.collection = function(name, options) {
|
|
1351
1368
|
const defaultOptions = {
|
|
1352
|
-
autoIndex: this.config.autoIndex
|
|
1353
|
-
autoCreate: this.config.autoCreate
|
|
1354
|
-
autoSearchIndex: this.config.autoSearchIndex
|
|
1369
|
+
autoIndex: this.config.autoIndex ?? this.base.options.autoIndex,
|
|
1370
|
+
autoCreate: this.config.autoCreate ?? this.base.options.autoCreate,
|
|
1371
|
+
autoSearchIndex: this.config.autoSearchIndex ?? this.base.options.autoSearchIndex
|
|
1355
1372
|
};
|
|
1356
1373
|
options = Object.assign({}, defaultOptions, options ? clone(options) : {});
|
|
1357
1374
|
options.$wasForceClosed = this.$wasForceClosed;
|
|
1358
|
-
const Collection = this.base
|
|
1375
|
+
const Collection = this.base?.__driver?.Collection || driver.get().Collection;
|
|
1359
1376
|
if (!(name in this.collections)) {
|
|
1360
1377
|
this.collections[name] = new Collection(name, this, options);
|
|
1361
1378
|
}
|
|
@@ -1376,7 +1393,7 @@ Connection.prototype.collection = function(name, options) {
|
|
|
1376
1393
|
* db.model('Test', new Schema({})); // Prints "Applied"
|
|
1377
1394
|
*
|
|
1378
1395
|
* @param {Function} fn plugin callback
|
|
1379
|
-
* @param {
|
|
1396
|
+
* @param {object} [opts] optional options
|
|
1380
1397
|
* @return {Connection} this
|
|
1381
1398
|
* @see plugins https://mongoosejs.com/docs/plugins.html
|
|
1382
1399
|
* @api public
|
|
@@ -1411,11 +1428,11 @@ Connection.prototype.plugin = function(fn, opts) {
|
|
|
1411
1428
|
* const collectionName = 'actor'
|
|
1412
1429
|
* const M = conn.model('Actor', schema, collectionName)
|
|
1413
1430
|
*
|
|
1414
|
-
* @param {
|
|
1431
|
+
* @param {string|Function} name the model name or class extending Model
|
|
1415
1432
|
* @param {Schema} [schema] a schema. necessary when defining a model
|
|
1416
|
-
* @param {
|
|
1417
|
-
* @param {
|
|
1418
|
-
* @param {
|
|
1433
|
+
* @param {string} [collection] name of mongodb collection (optional) if not given it will be induced from model name
|
|
1434
|
+
* @param {object} [options]
|
|
1435
|
+
* @param {boolean} [options.overwriteModels=false] If true, overwrite existing models with the same name to avoid `OverwriteModelError`
|
|
1419
1436
|
* @see Mongoose#model https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.model()
|
|
1420
1437
|
* @return {Model} The compiled model
|
|
1421
1438
|
* @api public
|
|
@@ -1448,7 +1465,7 @@ Connection.prototype.model = function model(name, schema, collection, options) {
|
|
|
1448
1465
|
}
|
|
1449
1466
|
}
|
|
1450
1467
|
if (schema && !schema.instanceOfSchema) {
|
|
1451
|
-
throw new
|
|
1468
|
+
throw new MongooseError('The 2nd parameter to `mongoose.model()` should be a ' +
|
|
1452
1469
|
'schema or a POJO');
|
|
1453
1470
|
}
|
|
1454
1471
|
|
|
@@ -1456,7 +1473,7 @@ Connection.prototype.model = function model(name, schema, collection, options) {
|
|
|
1456
1473
|
const opts = Object.assign(defaultOptions, options, { connection: this });
|
|
1457
1474
|
if (this.models[name] && !collection && opts.overwriteModels !== true) {
|
|
1458
1475
|
// model exists but we are not subclassing with custom collection
|
|
1459
|
-
if (schema
|
|
1476
|
+
if (schema?.instanceOfSchema && schema !== this.models[name].schema) {
|
|
1460
1477
|
throw new MongooseError.OverwriteModelError(name);
|
|
1461
1478
|
}
|
|
1462
1479
|
return this.models[name];
|
|
@@ -1464,7 +1481,7 @@ Connection.prototype.model = function model(name, schema, collection, options) {
|
|
|
1464
1481
|
|
|
1465
1482
|
let model;
|
|
1466
1483
|
|
|
1467
|
-
if (schema
|
|
1484
|
+
if (schema?.instanceOfSchema) {
|
|
1468
1485
|
applyPlugins(schema, this.plugins, null, '$connectionPluginsApplied');
|
|
1469
1486
|
|
|
1470
1487
|
// compile a model
|
|
@@ -1537,7 +1554,7 @@ Connection.prototype.model = function model(name, schema, collection, options) {
|
|
|
1537
1554
|
* });
|
|
1538
1555
|
*
|
|
1539
1556
|
* @api public
|
|
1540
|
-
* @param {
|
|
1557
|
+
* @param {string|RegExp} name if string, the name of the model to remove. If regexp, removes all models whose name matches the regexp.
|
|
1541
1558
|
* @return {Connection} this
|
|
1542
1559
|
*/
|
|
1543
1560
|
|
|
@@ -1561,7 +1578,7 @@ Connection.prototype.deleteModel = function deleteModel(name) {
|
|
|
1561
1578
|
}
|
|
1562
1579
|
}
|
|
1563
1580
|
} else {
|
|
1564
|
-
throw new
|
|
1581
|
+
throw new MongooseError('First parameter to `deleteModel()` must be a string ' +
|
|
1565
1582
|
'or regexp, got "' + name + '"');
|
|
1566
1583
|
}
|
|
1567
1584
|
|
|
@@ -1593,27 +1610,14 @@ Connection.prototype.deleteModel = function deleteModel(name) {
|
|
|
1593
1610
|
*
|
|
1594
1611
|
* @api public
|
|
1595
1612
|
* @param {Array} [pipeline]
|
|
1596
|
-
* @param {
|
|
1613
|
+
* @param {object} [options] passed without changes to [the MongoDB driver's `Db#watch()` function](https://mongodb.github.io/node-mongodb-native/7.0/classes/Db.html#watch)
|
|
1597
1614
|
* @return {ChangeStream} mongoose-specific change stream wrapper, inherits from EventEmitter
|
|
1598
1615
|
*/
|
|
1599
1616
|
|
|
1600
1617
|
Connection.prototype.watch = function watch(pipeline, options) {
|
|
1601
|
-
const
|
|
1602
|
-
immediate(() => {
|
|
1603
|
-
if (this.readyState === STATES.connecting) {
|
|
1604
|
-
this.once('open', function() {
|
|
1605
|
-
const driverChangeStream = this.db.watch(pipeline, options);
|
|
1606
|
-
cb(null, driverChangeStream);
|
|
1607
|
-
});
|
|
1608
|
-
} else {
|
|
1609
|
-
const driverChangeStream = this.db.watch(pipeline, options);
|
|
1610
|
-
cb(null, driverChangeStream);
|
|
1611
|
-
}
|
|
1612
|
-
});
|
|
1613
|
-
};
|
|
1618
|
+
const changeStreamPromise = this._waitForConnect().then(() => this.db.watch(pipeline, options));
|
|
1614
1619
|
|
|
1615
|
-
|
|
1616
|
-
return changeStream;
|
|
1620
|
+
return new ChangeStream(changeStreamPromise, pipeline, options);
|
|
1617
1621
|
};
|
|
1618
1622
|
|
|
1619
1623
|
/**
|
|
@@ -1643,7 +1647,7 @@ Connection.prototype.asPromise = async function asPromise() {
|
|
|
1643
1647
|
/**
|
|
1644
1648
|
* Returns an array of model names created on this connection.
|
|
1645
1649
|
* @api public
|
|
1646
|
-
* @return {
|
|
1650
|
+
* @return {Array<string>}
|
|
1647
1651
|
*/
|
|
1648
1652
|
|
|
1649
1653
|
Connection.prototype.modelNames = function modelNames() {
|
|
@@ -1656,7 +1660,7 @@ Connection.prototype.modelNames = function modelNames() {
|
|
|
1656
1660
|
* password is not required.
|
|
1657
1661
|
*
|
|
1658
1662
|
* @api private
|
|
1659
|
-
* @return {
|
|
1663
|
+
* @return {boolean} true if the connection should be authenticated after it is opened, otherwise false.
|
|
1660
1664
|
*/
|
|
1661
1665
|
Connection.prototype.shouldAuthenticate = function shouldAuthenticate() {
|
|
1662
1666
|
return this.user != null &&
|
|
@@ -1668,11 +1672,11 @@ Connection.prototype.shouldAuthenticate = function shouldAuthenticate() {
|
|
|
1668
1672
|
* password to authenticate according to the auth objects passed into the openUri methods.
|
|
1669
1673
|
*
|
|
1670
1674
|
* @api private
|
|
1671
|
-
* @return {
|
|
1675
|
+
* @return {boolean} true if the authentication mechanism specified in the options object requires
|
|
1672
1676
|
* a password, otherwise false.
|
|
1673
1677
|
*/
|
|
1674
1678
|
Connection.prototype.authMechanismDoesNotRequirePassword = function authMechanismDoesNotRequirePassword() {
|
|
1675
|
-
if (this.options
|
|
1679
|
+
if (this.options?.auth) {
|
|
1676
1680
|
return noPasswordAuthMechanisms.indexOf(this.options.auth.authMechanism) >= 0;
|
|
1677
1681
|
}
|
|
1678
1682
|
return true;
|
|
@@ -1684,9 +1688,9 @@ Connection.prototype.authMechanismDoesNotRequirePassword = function authMechanis
|
|
|
1684
1688
|
* but in some authentication methods, a password is not required for authentication so only a username
|
|
1685
1689
|
* is required.
|
|
1686
1690
|
*
|
|
1687
|
-
* @param {
|
|
1691
|
+
* @param {object} [options] the options object passed into the openUri methods.
|
|
1688
1692
|
* @api private
|
|
1689
|
-
* @return {
|
|
1693
|
+
* @return {boolean} true if the provided options object provides enough data to authenticate with,
|
|
1690
1694
|
* otherwise false.
|
|
1691
1695
|
*/
|
|
1692
1696
|
Connection.prototype.optionsProvideAuthenticationData = function optionsProvideAuthenticationData(options) {
|
|
@@ -1696,7 +1700,7 @@ Connection.prototype.optionsProvideAuthenticationData = function optionsProvideA
|
|
|
1696
1700
|
};
|
|
1697
1701
|
|
|
1698
1702
|
/**
|
|
1699
|
-
* Returns the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/
|
|
1703
|
+
* Returns the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/7.0/classes/MongoClient.html) instance
|
|
1700
1704
|
* that this connection uses to talk to MongoDB.
|
|
1701
1705
|
*
|
|
1702
1706
|
* #### Example:
|
|
@@ -1715,7 +1719,7 @@ Connection.prototype.getClient = function getClient() {
|
|
|
1715
1719
|
};
|
|
1716
1720
|
|
|
1717
1721
|
/**
|
|
1718
|
-
* Set the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/
|
|
1722
|
+
* Set the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/7.0/classes/MongoClient.html) instance
|
|
1719
1723
|
* that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
|
|
1720
1724
|
* reuse it.
|
|
1721
1725
|
*
|
|
@@ -1748,9 +1752,9 @@ Connection.prototype.createClient = function createClient() {
|
|
|
1748
1752
|
/**
|
|
1749
1753
|
* Syncs all the indexes for the models registered with this connection.
|
|
1750
1754
|
*
|
|
1751
|
-
* @param {
|
|
1752
|
-
* @param {
|
|
1753
|
-
* @return {Promise<
|
|
1755
|
+
* @param {object} [options]
|
|
1756
|
+
* @param {boolean} [options.continueOnError] `false` by default. If set to `true`, mongoose will not throw an error if one model syncing failed, and will return an object where the keys are the names of the models, and the values are the results/errors for each model.
|
|
1757
|
+
* @return {Promise<object>} Returns a Promise, when the Promise resolves the value is a list of the dropped indexes.
|
|
1754
1758
|
*/
|
|
1755
1759
|
Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
1756
1760
|
const result = {};
|
|
@@ -1772,7 +1776,7 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1772
1776
|
}
|
|
1773
1777
|
}
|
|
1774
1778
|
|
|
1775
|
-
if (!continueOnError &&
|
|
1779
|
+
if (!continueOnError && utils.hasOwnKeys(errorsMap)) {
|
|
1776
1780
|
const message = Object.entries(errorsMap).map(([modelName, err]) => `${modelName}: ${err.message}`).join(', ');
|
|
1777
1781
|
const syncIndexesError = new SyncIndexesError(message, errorsMap);
|
|
1778
1782
|
throw syncIndexesError;
|
|
@@ -1782,7 +1786,7 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1782
1786
|
};
|
|
1783
1787
|
|
|
1784
1788
|
/**
|
|
1785
|
-
* Switches to a different database using the same [connection pool](https://mongoosejs.com/docs/
|
|
1789
|
+
* Switches to a different database using the same [connection pool](https://mongoosejs.com/docs/connections.html#connection_pools).
|
|
1786
1790
|
*
|
|
1787
1791
|
* Returns a new connection object, with the new db.
|
|
1788
1792
|
*
|
|
@@ -1799,10 +1803,9 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1799
1803
|
*
|
|
1800
1804
|
* @method useDb
|
|
1801
1805
|
* @memberOf Connection
|
|
1802
|
-
* @param {
|
|
1803
|
-
* @param {
|
|
1804
|
-
* @param {
|
|
1805
|
-
* @param {Boolean} [options.noListener=false] If true, the connection object will not make the db listen to events on the original connection. See [issue #9961](https://github.com/Automattic/mongoose/issues/9961).
|
|
1806
|
+
* @param {string} name The database name
|
|
1807
|
+
* @param {object} [options]
|
|
1808
|
+
* @param {boolean} [options.useCache=false] If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object.
|
|
1806
1809
|
* @return {Connection} New Connection Object
|
|
1807
1810
|
* @api public
|
|
1808
1811
|
*/
|
|
@@ -1813,8 +1816,8 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1813
1816
|
* @method aggregate
|
|
1814
1817
|
* @memberOf Connection
|
|
1815
1818
|
* @param {Array} pipeline
|
|
1816
|
-
* @param {
|
|
1817
|
-
* @param {
|
|
1819
|
+
* @param {object} [options]
|
|
1820
|
+
* @param {boolean} [options.cursor=false] If true, make the Aggregate resolve to a Mongoose AggregationCursor rather than an array
|
|
1818
1821
|
* @return {Aggregate} Aggregation wrapper
|
|
1819
1822
|
* @api public
|
|
1820
1823
|
*/
|
|
@@ -1837,7 +1840,7 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1837
1840
|
*
|
|
1838
1841
|
* @method removeDb
|
|
1839
1842
|
* @memberOf Connection
|
|
1840
|
-
* @param {
|
|
1843
|
+
* @param {string} name The database name
|
|
1841
1844
|
* @return {Connection} this
|
|
1842
1845
|
* @api public
|
|
1843
1846
|
*/
|