diff --git a/CHANGELOG.md b/CHANGELOG.md index 70fce901f8..2d484e447f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +<<<<<<< HEAD 8.9.1 / 2024-12-16 ================== * fix(connection): remove heartbeat check in load balanced mode #15089 #15042 #14812 @@ -31,7 +32,17 @@ ================== * fix: disallow using $where in match * perf: cache results from getAllSubdocs() on saveOptions, only loop through known subdoc properties #15055 #15029 - * fix(model+query): support overwriteDiscriminatorKey for bulkWrite updateOne and updateMany, allow inferring discriminator key from update #15046 #15040 + * fix(model+query): support overwriteDiscriminatorKey for bulkWrite updateOne and updateMany, allow inferring discriminator key from update #15046 #15040 + +7.8.3 / 2024-11-26 +================== + * fix: disallow using $where in match + * fix(projection): avoid setting projection to unknown exclusive/inclusive if elemMatch on a Date, ObjectId, etc. #14894 #14893 + * docs(migrating_to_7): add note about keepAlive to Mongoose 7 migration guide #15032 #13431 + +6.13.5 / 2024-11-26 +=================== + * fix: disallow using $where in match 8.8.2 / 2024-11-18 ================== @@ -41,6 +52,11 @@ * types(cursor): correct asyncIterator and asyncDispose for TypeScript with lib: 'esnext' #15038 * docs(migrating_to_8): add note about removing findByIdAndRemove #15024 [dragontaek-lee](https://github.com/dragontaek-lee) +6.13.4 / 2024-11-15 +=================== + * fix: save execution stack in query as string #15043 #15039 + * docs: clarify strictQuery default will flip-flop in "Migrating to 6.x" #14998 [markstos](https://github.com/markstos) + 8.8.1 / 2024-11-08 ================== * perf: make a few micro-optimizations to help speed up findOne() #15022 #14906 @@ -62,7 +78,6 @@ * types: use globalThis instead of global for NativeDate #14992 #14988 * docs(change-streams): fix markdown syntax highlighting for script output example #14994 - 8.7.3 / 2024-10-25 ================== * fix(cursor): close underlying query cursor when calling destroy() #14982 #14966 @@ -110,6 +125,10 @@ ================== * fix(projection): avoid setting projection to unknown exclusive/inclusive if elemMatch on a Date, ObjectId, etc. #14894 #14893 +6.13.3 / 2024-09-23 +=================== + * docs(migrating_to_6): document that Lodash _.isEmpty() with ObjectId() as a parameter returns true in Mongoose 6 #11152 + 8.6.3 / 2024-09-17 ================== * fix: make getters convert uuid to string when calling toObject() and toJSON() #14890 #14869 diff --git a/docs/migrating_to_6.md b/docs/migrating_to_6.md index 9455c83577..1f8a632f7d 100644 --- a/docs/migrating_to_6.md +++ b/docs/migrating_to_6.md @@ -50,9 +50,11 @@ If you're still on Mongoose 4.x, please read the [Mongoose 4.x to 5.x migration * [SchemaType `set` parameters now use `priorValue` as the second parameter instead of `self`](#schematype-set-parameters) * [No default model for `Query.prototype.populate()`](#no-default-model-for-query-prototype-populate) * [`toObject()` and `toJSON()` Use Nested Schema `minimize`](#toobject-and-tojson-use-nested-schema-minimize) -* [TypeScript changes](#typescript-changes) * [Removed `reconnectTries` and `reconnectInterval` options](#removed-reconnecttries-and-reconnectinterval-options) * [MongoDB Driver's New URL Parser Incompatible with Some npm Packages](#mongodb-drivers-new-url-parser-incompatible-with-some-npm-packages) +* [Lodash `.isEmpty()` returns false for ObjectIds](#lodash-object-id) +* [mongoose.modelSchemas removed](#model-schemas) +* [TypeScript changes](#typescript-changes) ## Version Requirements {#version-requirements} @@ -144,9 +146,16 @@ if (existingUser) { ## `strictQuery` is now equal to `strict` by default {#strictquery-is-removed-and-replaced-by-strict} ~Mongoose no longer supports a `strictQuery` option. You must now use `strict`.~ -As of Mongoose 6.0.10, we brought back the `strictQuery` option. -However, `strictQuery` is tied to `strict` by default. -This means that, by default, Mongoose will filter out query filter properties that are not in the schema. +As of Mongoose 6.0.10, we brought back the `strictQuery` option. In Mongoose 6, `strictQuery` is set to `strict` by default. This means that, by default, Mongoose will filter out query filter properties that are not in the schema. + +However, this behavior was a source of confusion in some cases, so in Mongoose 7, this default changes back to `false`. So if you want to retain the default behavior of Mongoose 5 as well as Mongoose 7 and later, you can also disable `strictQuery` globally to override: + +```javascript +mongoose.set('strictQuery', false); +``` +In a test suite, it may be useful to set `strictQuery` to `throw`, which will throw exceptions any time a query references schema that doesn't exist, which could help identify a bug in your tests or code. + +Here's an example of the effect of `strictQuery`: ```javascript const userSchema = new Schema({ name: String }); @@ -504,6 +513,40 @@ The MongoDB Node driver version that Mongoose 6 uses relies on a [URL parser mod This can lead to errors like `Invalid URL: mongodb+srv://username:password@development.xyz.mongodb.net/abc` if you use one of the incompatible packages. [You can find a list of incompatible packages here](https://mongoosejs.com/docs/incompatible_packages). +## Removed `reconnectTries` and `reconnectInterval` options {#removed-reconnecttries-and-reconnectinterval-options} + +The `reconnectTries` and `reconnectInterval` options have been removed since they are no longer necessary. + +The MongoDB node driver will always attempt to retry any operation for up to `serverSelectionTimeoutMS`, even if MongoDB is down for a long period of time. +So, it will never run out of retries or try to reconnect to MongoDB. + +## Lodash `.isEmpty()` returns true for ObjectIds #{lodash-object-id} + +Lodash's `isEmpty()` function returns true for primitives and primitive wrappers. +`ObjectId()` is an object wrapper that is treated as a primitive by Mongoose. +But starting in Mongoose 6, `_.isEmpty()` will return true for ObjectIds because of Lodash implementation details. + +An ObjectId in mongoose is never empty, so if you're using `isEmpty()` you should check for `instanceof ObjectId`. + +```javascript +if (!(val instanceof Types.ObjectId) && _.isEmpty(val)) { + // Handle empty object here +} +``` + +## Removed `mongoose.modelSchemas` #{model-schemas} + +The `mongoose.modelSchemas` property was removed. This may have been used to delete a model schema. + +```javascript +// before +delete mongoose.modelSchemas.User; + +// with Mongoose 6.x +delete mongoose.deleteModel('User'); +``` + + ## TypeScript changes The `Schema` class now takes 3 generic params instead of 4. The 3rd generic param, `SchemaDefinitionType`, is now the same as the 1st generic param `DocType`. Replace `new Schema(schemaDefinition)` with `new Schema(schemaDefinition)` @@ -541,10 +584,3 @@ schema.virtual('myVirtual').get(function() { this.name; // string }); ``` - -## Removed `reconnectTries` and `reconnectInterval` options {#removed-reconnecttries-and-reconnectinterval-options} - -The `reconnectTries` and `reconnectInterval` options have been removed since they are no longer necessary. - -The MongoDB node driver will always attempt to retry any operation for up to `serverSelectionTimeoutMS`, even if MongoDB is down for a long period of time. -So, it will never run out of retries or try to reconnect to MongoDB. diff --git a/docs/migrating_to_7.md b/docs/migrating_to_7.md index 21c3aa377c..ad9af6f9d1 100644 --- a/docs/migrating_to_7.md +++ b/docs/migrating_to_7.md @@ -23,6 +23,7 @@ If you're still on Mongoose 5.x, please read the [Mongoose 5.x to 6.x migration * [ObjectId bsontype now has lowercase d](#objectid-bsontype-now-has-lowercase-d) * [Removed support for custom promise libraries](#removed-support-for-custom-promise-libraries) * [Removed mapReduce](#removed-mapreduce) +* [Deprecated `keepAlive`](#deprecated-keepalive) * [TypeScript-specific changes](#typescript-specific-changes) * [Removed `LeanDocument` and support for `extends Document`](#removed-leandocument-and-support-for-extends-document) * [New parameters for `HydratedDocument`](#new-parameters-for-hydrateddocument) @@ -338,6 +339,12 @@ If you want to use Bluebird for all promises globally, you can do the following: global.Promise = require('bluebird'); ``` +## Deprecated `keepAlive` #{deprecated-keepalive} + +Before Mongoose 5.2.0, you needed to enable the `keepAlive` option to initiate [TCP keepalive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) to prevent `"connection closed"` errors. +However, `keepAlive` has been `true` by default since Mongoose 5.2.0, and the `keepAlive` is deprecated as of Mongoose 7.2.0. +Please remove `keepAlive` and `keepAliveInitialDelay` options from your Mongoose connections. + ## TypeScript-specific Changes {#typescript-specific-changes} ### Removed `LeanDocument` and support for `extends Document` {#removed-leandocument-and-support-for-extends-document}