diff --git a/lib/schema.js b/lib/schema.js index b02ec83109f..1461a95ac3a 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -936,6 +936,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) { if (options.hasOwnProperty('typePojoToMixed')) { childSchemaOptions.typePojoToMixed = options.typePojoToMixed; } + if (this._userProvidedOptions.hasOwnProperty('_id')) { childSchemaOptions._id = this._userProvidedOptions._id; } else if (Schema.Types.DocumentArray.defaultOptions && diff --git a/lib/schema/SingleNestedPath.js b/lib/schema/SingleNestedPath.js index dc7f11ec5f8..5b54e9a86ea 100644 --- a/lib/schema/SingleNestedPath.js +++ b/lib/schema/SingleNestedPath.js @@ -316,6 +316,8 @@ SingleNestedPath.prototype.discriminator = function(name, schema, value) { * @api public */ +SingleNestedPath.defaultOptions = {}; + SingleNestedPath.set = SchemaType.set; /*! diff --git a/lib/schema/documentarray.js b/lib/schema/documentarray.js index c263fd66255..81ee5f79405 100644 --- a/lib/schema/documentarray.js +++ b/lib/schema/documentarray.js @@ -526,6 +526,8 @@ function scopePaths(array, fields, init) { * @api public */ +DocumentArrayPath.defaultOptions = {}; + DocumentArrayPath.set = SchemaType.set; /*! diff --git a/test/schema.documentarray.test.js b/test/schema.documentarray.test.js index 70d35378510..89937a538d1 100644 --- a/test/schema.documentarray.test.js +++ b/test/schema.documentarray.test.js @@ -112,6 +112,6 @@ describe('schema.documentarray', function() { assert.equal(doc.arr.length, 1); assert.ok(!doc.arr[0]._id); - mongoose.Schema.Types.DocumentArray.set('_id', true); + mongoose.Schema.Types.DocumentArray.defaultOptions = {}; }); }); diff --git a/test/schema.test.js b/test/schema.test.js index bbb82886605..462ce6c7bee 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -2001,13 +2001,13 @@ describe('schema', function() { }); assert.equal(schema.childSchemas.length, 2); - assert.equal(schema.childSchemas[0].schema, schema1); - assert.equal(schema.childSchemas[1].schema, schema2); + assert.strictEqual(schema.childSchemas[0].schema, schema1); + assert.strictEqual(schema.childSchemas[1].schema, schema2); schema = schema.clone(); assert.equal(schema.childSchemas.length, 2); - assert.equal(schema.childSchemas[0].schema, schema1); - assert.equal(schema.childSchemas[1].schema, schema2); + assert.strictEqual(schema.childSchemas[0].schema, schema1); + assert.strictEqual(schema.childSchemas[1].schema, schema2); done(); });