From 9b1ff1fe2ae42c985b31a57a084462a07619a546 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 27 Feb 2023 13:38:42 -0500 Subject: [PATCH] chore: release 7.0.0 --- CHANGELOG.md | 7 +++++++ docs/migrating_to_7.md | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e0c6f62f8..a85230ab0d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +7.0.0 / 2023-02-27 +================== + * BREAKING CHANGE: copy schema options when merging schemas using new Schema() or Schema.prototype.add() #13092 + * feat(types): export mongodb types more robustly #12948 [simon-abbott](https://github.com/simon-abbott) + * docs: fix populate docs #13090 [hasezoey](https://github.com/hasezoey) + * docs(migrating_to_6): added info about removal of reconnectTries and reconnectInterval options #13083 [lpizzinidev](https://github.com/lpizzinidev) + 7.0.0-rc0 / 2023-02-23 ====================== * BREAKING CHANGE: remove support for callbacks #11431 diff --git a/docs/migrating_to_7.md b/docs/migrating_to_7.md index c2474e5d13e..1c77422f051 100644 --- a/docs/migrating_to_7.md +++ b/docs/migrating_to_7.md @@ -17,6 +17,7 @@ If you're still on Mongoose 5.x, please read the [Mongoose 5.x to 6.x migration * [Removed `update()`](#removed-update) * [Discriminator schemas use base schema options by default](#discriminator-schemas-use-base-schema-options-by-default) * [Removed `castForQueryWrapper()`, updated `castForQuery()` signature](#removed-castforquerywrapper) +* [Copy schema options in `Schema.prototype.add()`](#copy-schema-options-in-schema-prototype-add) * [ObjectId bsontype now has lowercase d](#objectid-bsontype-now-has-lowercase-d) * [TypeScript-specific changes](#typescript-specific-changes) * [Removed `LeanDocument` and support for `extends Document`](#removed-leandocument-and-support-for-extends-document) @@ -217,6 +218,26 @@ MySchemaType.prototype.castForQuery = function($conditional, value, context) { }; ``` +

Copy Schema options in Schema.prototype.add()

+ +Mongoose now copies user defined schema options when adding one schema to another. +For example, `childSchema` below will get `baseSchema`'s `id` and `toJSON` options. + +```javascript +const baseSchema = new Schema({ created: Date }, { id: true, toJSON: { virtuals: true } }); +const childSchema = new Schema([baseSchema, { name: String }]); + +childSchema.options.toJSON; // { virtuals: true } in Mongoose 7. undefined in Mongoose 6. +``` + +This applies both when creating a new schema using an array of schemas, as well as when calling `add()` as follows. + +```javascript +childSchema.add(new Schema({}, { toObject: { virtuals: true } })); + +childSchema.options.toObject; // { virtuals: true } in Mongoose 7. undefined in Mongoose 6. +``` +

ObjectId bsontype now has lowercase d

The internal `_bsontype` property on ObjectIds is equal to `'ObjectId'` in Mongoose 7, as opposed to `'ObjectID'` in Mongoose 6.