diff --git a/lib/schema.js b/lib/schema.js index 70558e06f24..0bd2a8aadcd 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -1250,6 +1250,9 @@ Schema.prototype.interpretAsType = function(path, obj, options) { if (options.hasOwnProperty('strict')) { childSchemaOptions.strict = options.strict; } + if (options.hasOwnProperty('strictQuery')) { + childSchemaOptions.strictQuery = options.strictQuery; + } if (this._userProvidedOptions.hasOwnProperty('_id')) { childSchemaOptions._id = this._userProvidedOptions._id; diff --git a/test/schema.documentarray.test.js b/test/schema.documentarray.test.js index 3217e165d88..d9ccb6c1f6b 100644 --- a/test/schema.documentarray.test.js +++ b/test/schema.documentarray.test.js @@ -75,6 +75,15 @@ describe('schema.documentarray', function() { done(); }); + it('propagates strictQuery to implicitly created schemas (gh-12796)', function() { + const schema = new Schema({ + arr: [{ name: String }] + }, { strictQuery: 'throw' }); + + assert.equal(schema.childSchemas.length, 1); + assert.equal(schema.childSchemas[0].schema.options.strictQuery, 'throw'); + }); + it('supports set with array of document arrays (gh-7799)', function() { const subSchema = new Schema({ title: String