mongoose 6.3.8 → 6.3.9
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/lib/connection.js +3 -4
- package/lib/document.js +1 -1
- package/lib/error/disconnected.js +3 -4
- package/lib/index.js +0 -4
- package/package.json +1 -1
- package/types/aggregate.d.ts +3 -0
- package/types/index.d.ts +8 -8
package/lib/connection.js
CHANGED
|
@@ -9,6 +9,7 @@ const EventEmitter = require('events').EventEmitter;
|
|
|
9
9
|
const Schema = require('./schema');
|
|
10
10
|
const STATES = require('./connectionstate');
|
|
11
11
|
const MongooseError = require('./error/index');
|
|
12
|
+
const DisconnectedError = require('./error/disconnected');
|
|
12
13
|
const SyncIndexesError = require('./error/syncIndexes');
|
|
13
14
|
const PromiseProvider = require('./promise_provider');
|
|
14
15
|
const ServerSelectionError = require('./error/serverSelection');
|
|
@@ -565,8 +566,7 @@ function _wrapConnHelper(fn) {
|
|
|
565
566
|
const argsWithoutCb = typeof cb === 'function' ?
|
|
566
567
|
Array.prototype.slice.call(arguments, 0, arguments.length - 1) :
|
|
567
568
|
Array.prototype.slice.call(arguments);
|
|
568
|
-
const disconnectedError = new
|
|
569
|
-
' was disconnected when calling `' + fn.name + '`');
|
|
569
|
+
const disconnectedError = new DisconnectedError(this.id, fn.name);
|
|
570
570
|
|
|
571
571
|
return promiseOrCallback(cb, cb => {
|
|
572
572
|
immediate(() => {
|
|
@@ -1260,8 +1260,7 @@ Connection.prototype.deleteModel = function(name) {
|
|
|
1260
1260
|
*/
|
|
1261
1261
|
|
|
1262
1262
|
Connection.prototype.watch = function(pipeline, options) {
|
|
1263
|
-
const disconnectedError = new
|
|
1264
|
-
' was disconnected when calling `watch()`');
|
|
1263
|
+
const disconnectedError = new DisconnectedError(this.id, 'watch');
|
|
1265
1264
|
|
|
1266
1265
|
const changeStreamThunk = cb => {
|
|
1267
1266
|
immediate(() => {
|
package/lib/document.js
CHANGED
|
@@ -3388,7 +3388,7 @@ Document.prototype.$getAllSubdocs = function() {
|
|
|
3388
3388
|
}, seed);
|
|
3389
3389
|
} else if (val && !Array.isArray(val) && val.$isSingleNested) {
|
|
3390
3390
|
seed = Object.keys(val._doc).reduce(function(seed, path) {
|
|
3391
|
-
return docReducer(val
|
|
3391
|
+
return docReducer(val, seed, path);
|
|
3392
3392
|
}, seed);
|
|
3393
3393
|
seed.push(val);
|
|
3394
3394
|
} else if (val && utils.isMongooseDocumentArray(val)) {
|
|
@@ -16,10 +16,9 @@ class DisconnectedError extends MongooseError {
|
|
|
16
16
|
/**
|
|
17
17
|
* @param {String} connectionString
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
20
|
-
super('
|
|
21
|
-
|
|
22
|
-
'`server.reconnectInterval` to something higher.');
|
|
19
|
+
constructor(id, fnName) {
|
|
20
|
+
super('Connection ' + id +
|
|
21
|
+
' was disconnected when calling `' + fnName + '()`');
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
|
package/lib/index.js
CHANGED
|
@@ -260,8 +260,6 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
|
|
260
260
|
* @param {String} [options.user] username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility.
|
|
261
261
|
* @param {String} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility.
|
|
262
262
|
* @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
|
|
263
|
-
* @param {Number} [options.reconnectTries=30] If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections.
|
|
264
|
-
* @param {Number} [options.reconnectInterval=1000] See `reconnectTries` option above.
|
|
265
263
|
* @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
|
|
266
264
|
* @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).
|
|
267
265
|
* @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).
|
|
@@ -323,8 +321,6 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
|
|
323
321
|
* @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).
|
|
324
322
|
* @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.
|
|
325
323
|
* @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
|
|
326
|
-
* @param {Number} [options.reconnectTries=30] If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections.
|
|
327
|
-
* @param {Number} [options.reconnectInterval=1000] See `reconnectTries` option above.
|
|
328
324
|
* @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
|
|
329
325
|
* @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).
|
|
330
326
|
* @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.
|
package/package.json
CHANGED
package/types/aggregate.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -211,14 +211,14 @@ declare module 'mongoose' {
|
|
|
211
211
|
plugin(fn: (schema: Schema<DocType>, opts?: any) => void, opts?: any): this;
|
|
212
212
|
|
|
213
213
|
/** Defines a post hook for the model. */
|
|
214
|
-
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T>): this;
|
|
215
|
-
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
|
|
216
|
-
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T>): this;
|
|
217
|
-
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
|
|
218
|
-
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<
|
|
219
|
-
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<
|
|
220
|
-
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T>): this;
|
|
221
|
-
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
|
|
214
|
+
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
215
|
+
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
216
|
+
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
217
|
+
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
218
|
+
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
|
|
219
|
+
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
|
|
220
|
+
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
221
|
+
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
222
222
|
|
|
223
223
|
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
|
|
224
224
|
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
|