mongoose 6.5.2 → 6.5.5

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.
Files changed (95) hide show
  1. package/.mocharc.yml +2 -0
  2. package/dist/browser.umd.js +1148 -68091
  3. package/lib/aggregate.js +7 -7
  4. package/lib/browserDocument.js +1 -1
  5. package/lib/cast/boolean.js +1 -1
  6. package/lib/cast/number.js +1 -1
  7. package/lib/cast/string.js +1 -1
  8. package/lib/cast.js +3 -0
  9. package/lib/connection.js +19 -11
  10. package/lib/cursor/AggregationCursor.js +16 -5
  11. package/lib/cursor/QueryCursor.js +16 -5
  12. package/lib/document.js +31 -18
  13. package/lib/drivers/browser/objectid.js +2 -1
  14. package/lib/drivers/node-mongodb-native/ReadPreference.js +1 -1
  15. package/lib/drivers/node-mongodb-native/collection.js +6 -2
  16. package/lib/error/browserMissingSchema.js +1 -1
  17. package/lib/error/cast.js +2 -1
  18. package/lib/error/divergentArray.js +2 -1
  19. package/lib/error/missingSchema.js +2 -1
  20. package/lib/error/notFound.js +2 -1
  21. package/lib/error/overwriteModel.js +2 -1
  22. package/lib/error/strictPopulate.js +29 -0
  23. package/lib/error/validation.js +9 -7
  24. package/lib/error/validator.js +8 -4
  25. package/lib/helpers/clone.js +1 -1
  26. package/lib/helpers/discriminator/getConstructor.js +2 -1
  27. package/lib/helpers/discriminator/getDiscriminatorByValue.js +7 -6
  28. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +7 -6
  29. package/lib/helpers/document/compile.js +14 -2
  30. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +5 -1
  31. package/lib/helpers/get.js +2 -1
  32. package/lib/helpers/getConstructorName.js +2 -1
  33. package/lib/helpers/indexes/isIndexEqual.js +6 -6
  34. package/lib/helpers/isBsonType.js +2 -1
  35. package/lib/helpers/isMongooseObject.js +2 -2
  36. package/lib/helpers/isObject.js +1 -1
  37. package/lib/helpers/isSimpleValidator.js +1 -1
  38. package/lib/helpers/model/applyHooks.js +11 -0
  39. package/lib/helpers/model/applyMethods.js +11 -1
  40. package/lib/helpers/model/applyStatics.js +2 -1
  41. package/lib/helpers/model/castBulkWrite.js +7 -2
  42. package/lib/helpers/model/discriminator.js +3 -1
  43. package/lib/helpers/path/flattenObjectWithDottedPaths.js +3 -2
  44. package/lib/helpers/pluralize.js +1 -1
  45. package/lib/helpers/populate/assignRawDocsToIdStructure.js +5 -3
  46. package/lib/helpers/populate/assignVals.js +14 -3
  47. package/lib/helpers/populate/createPopulateQueryFilter.js +8 -2
  48. package/lib/helpers/populate/getModelsMapForPopulate.js +5 -4
  49. package/lib/helpers/populate/getSchemaTypes.js +3 -1
  50. package/lib/helpers/populate/markArraySubdocsPopulated.js +5 -1
  51. package/lib/helpers/projection/hasIncludedChildren.js +4 -1
  52. package/lib/helpers/projection/isPathExcluded.js +3 -2
  53. package/lib/helpers/projection/isSubpath.js +2 -1
  54. package/lib/helpers/query/applyQueryMiddleware.js +3 -2
  55. package/lib/helpers/query/castUpdate.js +14 -8
  56. package/lib/helpers/query/completeMany.js +3 -2
  57. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +7 -1
  58. package/lib/helpers/query/wrapThunk.js +3 -1
  59. package/lib/helpers/schema/getIndexes.js +7 -2
  60. package/lib/helpers/schema/getPath.js +4 -3
  61. package/lib/helpers/schema/idGetter.js +2 -1
  62. package/lib/helpers/setDefaultsOnInsert.js +15 -0
  63. package/lib/index.js +20 -12
  64. package/lib/model.js +219 -145
  65. package/lib/query.js +160 -65
  66. package/lib/queryhelpers.js +4 -4
  67. package/lib/schema/SubdocumentPath.js +1 -1
  68. package/lib/schema/array.js +2 -2
  69. package/lib/schema/date.js +2 -1
  70. package/lib/schema/documentarray.js +4 -3
  71. package/lib/schema/operators/helpers.js +2 -2
  72. package/lib/schema/operators/text.js +1 -1
  73. package/lib/schema/string.js +1 -1
  74. package/lib/schema.js +14 -5
  75. package/lib/schematype.js +17 -4
  76. package/lib/statemachine.js +13 -12
  77. package/lib/types/ArraySubdocument.js +13 -3
  78. package/lib/types/DocumentArray/methods/index.js +9 -5
  79. package/lib/types/array/methods/index.js +5 -4
  80. package/lib/types/map.js +3 -1
  81. package/lib/types/objectid.js +2 -2
  82. package/lib/types/subdocument.js +30 -8
  83. package/lib/utils.js +58 -31
  84. package/package.json +11 -11
  85. package/scripts/create-tarball.js +7 -0
  86. package/types/aggregate.d.ts +3 -3
  87. package/types/connection.d.ts +4 -4
  88. package/types/cursor.d.ts +1 -1
  89. package/types/document.d.ts +2 -2
  90. package/types/index.d.ts +13 -27
  91. package/types/indexes.d.ts +2 -2
  92. package/types/middlewares.d.ts +1 -1
  93. package/types/models.d.ts +14 -11
  94. package/types/pipelinestage.d.ts +1 -1
  95. package/types/query.d.ts +33 -16
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Determines if `path2` is a subpath of or equal to `path1`
5
5
  *
6
6
  * @param {string} path1
7
7
  * @param {string} path2
8
8
  * @return {Boolean}
9
+ * @api private
9
10
  */
10
11
 
11
12
  module.exports = function isSubpath(path1, path2) {
@@ -16,11 +16,12 @@ applyQueryMiddleware.middlewareFunctions = validOps.concat([
16
16
  'validate'
17
17
  ]);
18
18
 
19
- /*!
19
+ /**
20
20
  * Apply query middleware
21
21
  *
22
- * @param {Query} query constructor
22
+ * @param {Query} Query constructor
23
23
  * @param {Model} model
24
+ * @api private
24
25
  */
25
26
 
26
27
  function applyQueryMiddleware(Query, model) {
@@ -14,16 +14,17 @@ const schemaMixedSymbol = require('../../schema/symbols').schemaMixedSymbol;
14
14
  const setDottedPath = require('../path/setDottedPath');
15
15
  const utils = require('../../utils');
16
16
 
17
- /*!
17
+ /**
18
18
  * Casts an update op based on the given schema
19
19
  *
20
20
  * @param {Schema} schema
21
21
  * @param {Object} obj
22
- * @param {Object} options
22
+ * @param {Object} [options]
23
23
  * @param {Boolean} [options.overwrite] defaults to false
24
24
  * @param {Boolean|String} [options.strict] defaults to true
25
25
  * @param {Query} context passed to setters
26
26
  * @return {Boolean} true iff the update is non-empty
27
+ * @api private
27
28
  */
28
29
  module.exports = function castUpdate(schema, obj, options, context, filter) {
29
30
  if (obj == null) {
@@ -150,16 +151,17 @@ function castPipelineOperator(op, val) {
150
151
  throw new MongooseError('Invalid update pipeline operator: "' + op + '"');
151
152
  }
152
153
 
153
- /*!
154
+ /**
154
155
  * Walk each path of obj and cast its values
155
156
  * according to its schema.
156
157
  *
157
158
  * @param {Schema} schema
158
159
  * @param {Object} obj part of a query
159
160
  * @param {String} op the atomic operator ($pull, $set, etc)
160
- * @param {Object} options
161
+ * @param {Object} [options]
161
162
  * @param {Boolean|String} [options.strict]
162
163
  * @param {Query} context
164
+ * @param {Object} filter
163
165
  * @param {String} pref path prefix (internal only)
164
166
  * @return {Bool} true if this path has keys to update
165
167
  * @api private
@@ -407,9 +409,10 @@ function _appendError(error, query, key, aggregatedError) {
407
409
  return aggregatedError;
408
410
  }
409
411
 
410
- /*!
412
+ /**
411
413
  * These operators should be cast to numbers instead
412
414
  * of their path schema type.
415
+ * @api private
413
416
  */
414
417
 
415
418
  const numberOps = {
@@ -417,17 +420,19 @@ const numberOps = {
417
420
  $inc: 1
418
421
  };
419
422
 
420
- /*!
423
+ /**
421
424
  * These ops require no casting because the RHS doesn't do anything.
425
+ * @api private
422
426
  */
423
427
 
424
428
  const noCastOps = {
425
429
  $unset: 1
426
430
  };
427
431
 
428
- /*!
432
+ /**
429
433
  * These operators require casting docs
430
434
  * to real Documents for Update operations.
435
+ * @api private
431
436
  */
432
437
 
433
438
  const castOps = {
@@ -446,7 +451,7 @@ const overwriteOps = {
446
451
  $setOnInsert: 1
447
452
  };
448
453
 
449
- /*!
454
+ /**
450
455
  * Casts `val` according to `schema` and atomic `op`.
451
456
  *
452
457
  * @param {SchemaType} schema
@@ -454,6 +459,7 @@ const overwriteOps = {
454
459
  * @param {String} op the atomic operator ($pull, $set, etc)
455
460
  * @param {String} $conditional
456
461
  * @param {Query} context
462
+ * @param {String} path
457
463
  * @api private
458
464
  */
459
465
 
@@ -5,7 +5,7 @@ const immediate = require('../immediate');
5
5
 
6
6
  module.exports = completeMany;
7
7
 
8
- /*!
8
+ /**
9
9
  * Given a model and an array of docs, hydrates all the docs to be instances
10
10
  * of the model. Used to initialize docs returned from the db from `find()`
11
11
  *
@@ -13,10 +13,11 @@ module.exports = completeMany;
13
13
  * @param {Array} docs
14
14
  * @param {Object} fields the projection used, including `select` from schemas
15
15
  * @param {Object} userProvidedFields the user-specified projection
16
- * @param {Object} opts
16
+ * @param {Object} [opts]
17
17
  * @param {Array} [opts.populated]
18
18
  * @param {ClientSession} [opts.session]
19
19
  * @param {Function} callback
20
+ * @api private
20
21
  */
21
22
 
22
23
  function completeMany(model, docs, fields, userProvidedFields, opts, callback) {
@@ -5,9 +5,15 @@ const get = require('../get');
5
5
  const getDiscriminatorByValue = require('../discriminator/getDiscriminatorByValue');
6
6
  const updatedPathsByArrayFilter = require('../update/updatedPathsByArrayFilter');
7
7
 
8
- /*!
8
+ /**
9
9
  * Like `schema.path()`, except with a document, because impossible to
10
10
  * determine path type without knowing the embedded discriminator key.
11
+ * @param {Schema} schema
12
+ * @param {Object} [update]
13
+ * @param {Object} [filter]
14
+ * @param {String} path
15
+ * @param {Object} [options]
16
+ * @api private
11
17
  */
12
18
 
13
19
  module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, path, options) {
@@ -2,13 +2,15 @@
2
2
 
3
3
  const MongooseError = require('../../error/mongooseError');
4
4
 
5
- /*!
5
+ /**
6
6
  * A query thunk is the function responsible for sending the query to MongoDB,
7
7
  * like `Query#_findOne()` or `Query#_execUpdate()`. The `Query#exec()` function
8
8
  * calls a thunk. The term "thunk" here is the traditional Node.js definition:
9
9
  * a function that takes exactly 1 parameter, a callback.
10
10
  *
11
11
  * This function defines common behavior for all query thunks.
12
+ * @param {Function} fn
13
+ * @api private
12
14
  */
13
15
 
14
16
  module.exports = function wrapThunk(fn) {
@@ -4,9 +4,11 @@ const get = require('../get');
4
4
  const helperIsObject = require('../isObject');
5
5
  const decorateDiscriminatorIndexOptions = require('../indexes/decorateDiscriminatorIndexOptions');
6
6
 
7
- /*!
7
+ /**
8
8
  * Gather all indexes defined in the schema, including single nested,
9
9
  * document arrays, and embedded discriminators.
10
+ * @param {Schema} schema
11
+ * @api private
10
12
  */
11
13
 
12
14
  module.exports = function getIndexes(schema) {
@@ -120,11 +122,14 @@ module.exports = function getIndexes(schema) {
120
122
  }
121
123
  }
122
124
 
123
- /*!
125
+ /**
124
126
  * Checks for indexes added to subdocs using Schema.index().
125
127
  * These indexes need their paths prefixed properly.
126
128
  *
127
129
  * schema._indexes = [ [indexObj, options], [indexObj, options] ..]
130
+ * @param {Schema} schema
131
+ * @param {String} prefix
132
+ * @api private
128
133
  */
129
134
 
130
135
  function fixSubIndexPaths(schema, prefix) {
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ const numberRE = /^\d+$/;
4
+
5
+ /**
4
6
  * Behaves like `Schema#path()`, except for it also digs into arrays without
5
7
  * needing to put `.0.`, so `getPath(schema, 'docArr.elProp')` works.
8
+ * @api private
6
9
  */
7
10
 
8
- const numberRE = /^\d+$/;
9
-
10
11
  module.exports = function getPath(schema, path) {
11
12
  let schematype = schema.path(path);
12
13
  if (schematype != null) {
@@ -18,8 +18,9 @@ module.exports = function addIdGetter(schema) {
18
18
  return schema;
19
19
  };
20
20
 
21
- /*!
21
+ /**
22
22
  * Returns this documents _id cast to a string.
23
+ * @api private
23
24
  */
24
25
 
25
26
  function idGetter() {
@@ -105,6 +105,8 @@ function isModified(modified, path) {
105
105
  if (modified[path]) {
106
106
  return true;
107
107
  }
108
+
109
+ // Is any parent path of `path` modified?
108
110
  const sp = path.split('.');
109
111
  let cur = sp[0];
110
112
  for (let i = 1; i < sp.length; ++i) {
@@ -113,5 +115,18 @@ function isModified(modified, path) {
113
115
  }
114
116
  cur += '.' + sp[i];
115
117
  }
118
+
119
+ // Is any child of `path` modified?
120
+ const modifiedKeys = Object.keys(modified);
121
+ if (modifiedKeys.length) {
122
+ const parentPath = path + '.';
123
+
124
+ for (const modifiedPath of modifiedKeys) {
125
+ if (modifiedPath.slice(0, path.length + 1) === parentPath) {
126
+ return true;
127
+ }
128
+ }
129
+ }
130
+
116
131
  return false;
117
132
  }
package/lib/index.js CHANGED
@@ -293,20 +293,20 @@ Mongoose.prototype.get = Mongoose.prototype.set;
293
293
  * db = mongoose.createConnection();
294
294
  * db.openUri('localhost', 'database', port, [opts]);
295
295
  *
296
- * @param {String} [uri] a mongodb:// URI
297
- * @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](https://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html), except for 4 mongoose-specific options explained below.
296
+ * @param {String} uri mongodb URI to connect to
297
+ * @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/MongoClientOptions.html), except for 4 mongoose-specific options explained below.
298
298
  * @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.
299
299
  * @param {String} [options.dbName] The name of the database you want to use. If not provided, Mongoose uses the database name from connection string.
300
300
  * @param {String} [options.user] username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility.
301
301
  * @param {String} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility.
302
302
  * @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
303
- * @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
303
+ * @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/MongoClientOptions.html#promiseLibrary).
304
304
  * @param {Number} [options.maxPoolSize=5] 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).
305
305
  * @param {Number} [options.minPoolSize=1] 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).
306
306
  * @param {Number} [options.connectTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).
307
307
  * @param {Number} [options.socketTimeoutMS=30000] 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. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. 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.
308
308
  * @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.
309
- * @return {Connection} the created Connection object. Connections are not thenable, so you can't do `await mongoose.createConnection()`. To await use mongoose.createConnection(uri).asPromise() instead.
309
+ * @return {Connection} the created Connection object. Connections are not thenable, so you can't do `await mongoose.createConnection()`. To await use `mongoose.createConnection(uri).asPromise()` instead.
310
310
  * @api public
311
311
  */
312
312
 
@@ -349,8 +349,8 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
349
349
  * // if error is truthy, the initial connection failed.
350
350
  * })
351
351
  *
352
- * @param {String} uri(s)
353
- * @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](https://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html), except for 4 mongoose-specific options explained below.
352
+ * @param {String} uri mongodb URI to connect to
353
+ * @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/MongoClientOptions.html), except for 4 mongoose-specific options explained below.
354
354
  * @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.
355
355
  * @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.
356
356
  * @param {String} [options.dbName] The name of the database we want to use. If not provided, use database name from connection string.
@@ -361,13 +361,13 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
361
361
  * @param {Number} [options.serverSelectionTimeoutMS] If `useUnifiedTopology = true`, 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).
362
362
  * @param {Number} [options.heartbeatFrequencyMS] If `useUnifiedTopology = true`, 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.
363
363
  * @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
364
- * @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
364
+ * @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/MongoClientOptions.html#promiseLibrary).
365
365
  * @param {Number} [options.connectTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).
366
366
  * @param {Number} [options.socketTimeoutMS=30000] 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. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. 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.
367
367
  * @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.
368
368
  * @param {Boolean} [options.autoCreate=false] Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection.
369
369
  * @param {Function} [callback]
370
- * @see Mongoose#createConnection #index_Mongoose-createConnection
370
+ * @see Mongoose#createConnection /docs/api.html#mongoose_Mongoose-createConnection
371
371
  * @api public
372
372
  * @return {Promise} resolves to `this` if connection succeeded
373
373
  */
@@ -424,7 +424,7 @@ Mongoose.prototype.disconnect = function(callback) {
424
424
  * Sessions are scoped to a connection, so calling `mongoose.startSession()`
425
425
  * starts a session on the [default mongoose connection](/docs/api.html#mongoose_Mongoose-connection).
426
426
  *
427
- * @param {Object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html#startSession)
427
+ * @param {Object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/4.9/classes/MongoClient.html#startSession)
428
428
  * @param {Boolean} [options.causalConsistency=true] set to false to disable causal consistency
429
429
  * @param {Function} [callback]
430
430
  * @return {Promise<ClientSession>} promise that resolves to a MongoDB driver `ClientSession`
@@ -514,6 +514,14 @@ Mongoose.prototype.model = function(name, schema, collection, options) {
514
514
  schema = false;
515
515
  }
516
516
 
517
+ if (arguments.length === 1) {
518
+ const model = _mongoose.models[name];
519
+ if (!model) {
520
+ throw new MongooseError.MissingSchemaError(name);
521
+ }
522
+ return model;
523
+ }
524
+
517
525
  if (utils.isObject(schema) && !(schema instanceof Schema)) {
518
526
  schema = new Schema(schema);
519
527
  }
@@ -862,7 +870,7 @@ Mongoose.prototype.SchemaType = SchemaType;
862
870
  * _Alias of mongoose.Schema.Types for backwards compatibility._
863
871
  *
864
872
  * @property SchemaTypes
865
- * @see Schema.SchemaTypes #schema_Schema-Types
873
+ * @see Schema.SchemaTypes /docs/schematypes
866
874
  * @api public
867
875
  */
868
876
 
@@ -1262,10 +1270,10 @@ Mongoose.prototype.skipMiddlewareFunction = Kareem.skipWrappedFunction;
1262
1270
 
1263
1271
  Mongoose.prototype.overwriteMiddlewareResult = Kareem.overwriteResult;
1264
1272
 
1265
- /*!
1273
+ /**
1266
1274
  * The exports object is an instance of Mongoose.
1267
1275
  *
1268
- * @api public
1276
+ * @api private
1269
1277
  */
1270
1278
 
1271
1279
  const mongoose = module.exports = exports = new Mongoose({