Comparing version 8.6.4 to 8.7.0
@@ -109,2 +109,11 @@ 'use strict'; | ||
get: function() { | ||
// If connection thinks it is connected, but we haven't received a heartbeat in 2 heartbeat intervals, | ||
// that likely means the connection is stale (potentially due to frozen AWS Lambda container) | ||
if ( | ||
this._readyState === STATES.connected && | ||
this._lastHeartbeatAt != null && | ||
typeof this.client?.topology?.s?.description?.heartbeatFrequencyMS === 'number' && | ||
Date.now() - this._lastHeartbeatAt >= this.client.topology.s.description.heartbeatFrequencyMS * 2) { | ||
return STATES.disconnected; | ||
} | ||
return this._readyState; | ||
@@ -111,0 +120,0 @@ }, |
@@ -26,2 +26,7 @@ /*! | ||
this._listening = false; | ||
// Tracks the last time (as unix timestamp) the connection received a | ||
// serverHeartbeatSucceeded or serverHeartbeatFailed event from the underlying MongoClient. | ||
// If we haven't received one in a while (like due to a frozen AWS Lambda container) then | ||
// `readyState` is likely stale. | ||
this._lastHeartbeatAt = null; | ||
} | ||
@@ -110,2 +115,3 @@ | ||
newConn.db = _this.client.db(name, _opts); | ||
newConn._lastHeartbeatAt = _this._lastHeartbeatAt; | ||
newConn.onOpen(); | ||
@@ -414,2 +420,5 @@ } | ||
} | ||
client.on('serverHeartbeatSucceeded', () => { | ||
conn._lastHeartbeatAt = Date.now(); | ||
}); | ||
@@ -423,2 +432,5 @@ if (options.monitorCommands) { | ||
conn.onOpen(); | ||
if (client.topology?.s?.state === 'connected') { | ||
conn._lastHeartbeatAt = Date.now(); | ||
} | ||
@@ -425,0 +437,0 @@ for (const i in conn.collections) { |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const MongooseError = require('../../error/mongooseError'); | ||
const SchemaString = require('../../schema/string'); | ||
const StrictModeError = require('../../error/strict'); | ||
@@ -312,2 +313,16 @@ const ValidationError = require('../../error/validation'); | ||
hasKeys = true; | ||
} else if (op === '$rename') { | ||
const schematype = new SchemaString(`${prefix}${key}.$rename`); | ||
try { | ||
obj[key] = castUpdateVal(schematype, val, op, key, context, prefix + key); | ||
} catch (error) { | ||
aggregatedError = _appendError(error, context, key, aggregatedError); | ||
} | ||
if (obj[key] === void 0) { | ||
delete obj[key]; | ||
continue; | ||
} | ||
hasKeys = true; | ||
} else { | ||
@@ -377,6 +392,8 @@ const pathToCheck = (prefix + key); | ||
} else { | ||
// gh-1845 temporary fix: ignore $rename. See gh-3027 for tracking | ||
// improving this. | ||
if (op === '$rename') { | ||
hasKeys = true; | ||
if (obj[key] == null) { | ||
throw new CastError('String', obj[key], `${prefix}${key}.$rename`); | ||
} | ||
const schematype = new SchemaString(`${prefix}${key}.$rename`); | ||
obj[key] = schematype.castForQuery(null, obj[key], context); | ||
continue; | ||
@@ -383,0 +400,0 @@ } |
@@ -1727,2 +1727,21 @@ 'use strict'; | ||
/** | ||
* Returns the embedded schema type, if any. For arrays, document arrays, and maps, `getEmbeddedSchemaType()` | ||
* returns the schema type of the array's elements (or map's elements). For other types, `getEmbeddedSchemaType()` | ||
* returns `undefined`. | ||
* | ||
* #### Example: | ||
* | ||
* const schema = new Schema({ name: String, tags: [String] }); | ||
* schema.path('name').getEmbeddedSchemaType(); // undefined | ||
* schema.path('tags').getEmbeddedSchemaType(); // SchemaString { path: 'tags', ... } | ||
* | ||
* @returns {SchemaType} embedded schematype | ||
* @api public | ||
*/ | ||
SchemaType.prototype.getEmbeddedSchemaType = function getEmbeddedSchemaType() { | ||
return this.$embeddedSchemaType; | ||
}; | ||
/*! | ||
@@ -1729,0 +1748,0 @@ * Module exports. |
@@ -413,2 +413,3 @@ 'use strict'; | ||
_checkManualPopulation(this, arguments); | ||
_depopulateIfNecessary(this, arguments); | ||
@@ -695,2 +696,3 @@ const values = [].map.call(arguments, this._mapCast, this); | ||
_checkManualPopulation(this, values); | ||
_depopulateIfNecessary(this, values); | ||
@@ -1014,2 +1016,26 @@ values = [].map.call(values, this._mapCast, this); | ||
/*! | ||
* If `docs` isn't all instances of the right model, depopulate `arr` | ||
*/ | ||
function _depopulateIfNecessary(arr, docs) { | ||
const ref = arr == null ? | ||
null : | ||
arr[arraySchemaSymbol] && arr[arraySchemaSymbol].caster && arr[arraySchemaSymbol].caster.options && arr[arraySchemaSymbol].caster.options.ref || null; | ||
const parentDoc = arr[arrayParentSymbol]; | ||
const path = arr[arrayPathSymbol]; | ||
if (!ref || !parentDoc.populated(path)) { | ||
return; | ||
} | ||
for (const doc of docs) { | ||
if (doc == null) { | ||
continue; | ||
} | ||
if (typeof doc !== 'object' || doc instanceof String || doc instanceof Number || doc instanceof Buffer || utils.isMongooseType(doc)) { | ||
parentDoc.depopulate(path); | ||
break; | ||
} | ||
} | ||
} | ||
const returnVanillaArrayMethods = [ | ||
@@ -1016,0 +1042,0 @@ 'filter', |
{ | ||
"name": "mongoose", | ||
"description": "Mongoose MongoDB ODM", | ||
"version": "8.6.4", | ||
"version": "8.7.0", | ||
"author": "Guillermo Rauch <guillermo@learnboost.com>", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"kareem": "2.6.3", | ||
"mongodb": "6.8.0", | ||
"mongodb": "6.9.0", | ||
"mpath": "0.9.0", | ||
@@ -27,0 +27,0 @@ "mquery": "5.0.0", |
@@ -27,5 +27,2 @@ declare module 'mongoose' { | ||
/** This documents __v. */ | ||
__v?: any; | ||
/** Assert that a given path or paths is populated. Throws an error if not populated. */ | ||
@@ -32,0 +29,0 @@ $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit<this, keyof Paths> & Paths; |
@@ -141,2 +141,6 @@ /// <reference path="./aggregate.d.ts" /> | ||
export type Default__v<T> = T extends { __v?: infer U } | ||
? T | ||
: T & { __v?: number }; | ||
/** Helper type for getting the hydrated document type from the raw document type. The hydrated document type is what `new MyModel()` returns. */ | ||
@@ -151,8 +155,8 @@ export type HydratedDocument< | ||
TOverrides extends Record<string, never> ? | ||
Document<unknown, TQueryHelpers, DocType> & Require_id<DocType> : | ||
Document<unknown, TQueryHelpers, DocType> & Default__v<Require_id<DocType>> : | ||
IfAny< | ||
TOverrides, | ||
Document<unknown, TQueryHelpers, DocType> & Require_id<DocType>, | ||
Document<unknown, TQueryHelpers, DocType> & Default__v<Require_id<DocType>>, | ||
Document<unknown, TQueryHelpers, DocType> & MergeType< | ||
Require_id<DocType>, | ||
Default__v<Require_id<DocType>>, | ||
TOverrides | ||
@@ -159,0 +163,0 @@ > |
@@ -293,2 +293,5 @@ declare module 'mongoose' { | ||
/* Apply virtuals to the given POJO. */ | ||
applyVirtuals(obj: AnyObject, virtalsToApply?: string[]): AnyObject; | ||
/** | ||
@@ -295,0 +298,0 @@ * Sends multiple `insertOne`, `updateOne`, `updateMany`, `replaceOne`, |
@@ -235,2 +235,5 @@ declare module 'mongoose' { | ||
/** Gets this SchemaType's embedded SchemaType, if any */ | ||
getEmbeddedSchemaType<T = any, DocType = any>(): SchemaType<T, DocType> | undefined; | ||
/** | ||
@@ -237,0 +240,0 @@ * Defines this path as immutable. Mongoose prevents you from changing |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2728767
289
51580
+ Addedmongodb@6.9.0(transitive)
- Removedmongodb@6.8.0(transitive)
Updatedmongodb@6.9.0