Skip to content

Commit

Permalink
Merge branch 'master' into 8.10
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 10, 2025
2 parents 62ab149 + 39886fb commit dcca5ca
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 `<code>` 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3806,8 +3806,9 @@ Model.castObject = function castObject(obj, options) {
Model.castObject.call(schemaType.caster, val)
];
}

continue;
}
continue;
}
if (schemaType.$isSingleNested || schemaType.$isMongooseDocumentArrayElement) {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "8.9.3",
"version": "8.9.4",
"author": "Guillermo Rauch <[email protected]>",
"keywords": [
"mongodb",
Expand Down
23 changes: 23 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit dcca5ca

Please sign in to comment.