diff --git a/CHANGELOG.md b/CHANGELOG.md index 685c8500b1..de36d3a884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +8.9.4 / 2025-01-09 +================== + * fix(document): fix document not applying manual populate when using a function in schema.options.ref #15138 [IchirokuXVI](https://github.com/IchirokuXVI) + * fix(model): make Model.validate() static correctly cast document arrays #15169 #15164 + * fix(model): allow passing validateBeforeSave option to bulkSave() to skip validation #15161 #15156 + * fix(schema): allow multiple self-referencing discriminator schemas using Schema.prototype.discriminator #15142 #15120 + * types: avoid BufferToBinary<> wiping lean types when passed to generic functions #15160 #15158 + * docs: fix `` in header ids #15159 + * docs: fix header in field-level-encryption.md #15137 [damieng](https://github.com/damieng) + 8.9.3 / 2024-12-30 ================== * fix(schema): make duplicate index error a warning for now to prevent blocking upgrading #15135 #15112 #15109 @@ -1109,7 +1119,7 @@ * fix(document): isModified should not be triggered when setting a nested boolean to the same value as previously #12994 [lpizzinidev](https://github.com/lpizzinidev) * fix(document): save newly set defaults underneath single nested subdocuments #13002 #12905 * fix(update): handle custom discriminator model name when casting update #12947 [wassil](https://github.com/wassil) - * fix(connection): handles unique autoincrement ID for connections #12990 [lpizzinidev](https://github.com/lpizzinidev) + * fix(connection): handles unique autoincrement ID for connections #12990 [lpizzinidev](https://github.com/lpizzinidev) * fix(types): fix type of options of Model.aggregate #12933 [ghost91-](https://github.com/ghost91-) * fix(types): fix "near" aggregation operator input type #12954 [Jokero](https://github.com/Jokero) * fix(types): add missing Top operator to AccumulatorOperator type declaration #12952 [lpizzinidev](https://github.com/lpizzinidev) @@ -1138,7 +1148,7 @@ * docs(typescript): add notes about virtual context to Mongoose 6 migration and TypeScript virtuals docs #12912 #12806 * docs(schematypes): removed dead link and fixed formatting #12897 #12885 [lpizzinidev](https://github.com/lpizzinidev) * docs: fix link to lean api #12910 [manniL](https://github.com/manniL) - * docs: list all possible strings for schema.pre in one place #12868 + * docs: list all possible strings for schema.pre in one place #12868 * docs: add list of known incompatible npm packages #12892 [IslandRhythms](https://github.com/IslandRhythms) 6.8.3 / 2023-01-06 diff --git a/lib/model.js b/lib/model.js index addbd1b3bf..bd0490aae3 100644 --- a/lib/model.js +++ b/lib/model.js @@ -3806,8 +3806,9 @@ Model.castObject = function castObject(obj, options) { Model.castObject.call(schemaType.caster, val) ]; } + + continue; } - continue; } if (schemaType.$isSingleNested || schemaType.$isMongooseDocumentArrayElement) { try { diff --git a/package.json b/package.json index bcb729e3d7..453705f05e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongoose", "description": "Mongoose MongoDB ODM", - "version": "8.9.3", + "version": "8.9.4", "author": "Guillermo Rauch ", "keywords": [ "mongodb", diff --git a/test/model.test.js b/test/model.test.js index be87e5a438..b15a590e1f 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -7818,6 +7818,29 @@ describe('Model', function() { const obj = { sampleArray: { name: 'Taco' } }; assert.throws(() => Test.castObject(obj), /Tried to set nested object field `sampleArray` to primitive value/); }); + it('handles document arrays (gh-15164)', function() { + const barSchema = new mongoose.Schema({ + foo: { + type: mongoose.Schema.Types.String, + required: true + } + }, { _id: false }); + + const fooSchema = new mongoose.Schema({ + bars: { + type: [barSchema], + required: true + } + }); + + const Test = db.model('Test', fooSchema); + + let obj = Test.castObject({ bars: [] }); + assert.deepStrictEqual(obj.bars, []); + + obj = Test.castObject({ bars: [{ foo: 'bar' }] }); + assert.deepStrictEqual(obj.bars, [{ foo: 'bar' }]); + }); }); it('works if passing class that extends Document to `loadClass()` (gh-12254)', async function() {