diff --git a/lib/schema/documentArray.js b/lib/schema/documentArray.js index a10d2ec76b1..aa0c0d7984a 100644 --- a/lib/schema/documentArray.js +++ b/lib/schema/documentArray.js @@ -69,7 +69,7 @@ function SchemaDocumentArray(key, schema, options, schemaOptions) { const fn = this.defaultValue; - if (!('defaultValue' in this) || fn !== void 0) { + if (!('defaultValue' in this) || fn != null) { this.default(function() { let arr = fn.call(this); if (arr != null && !Array.isArray(arr)) { diff --git a/test/document.test.js b/test/document.test.js index c11f72753ee..5957556a867 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -3203,16 +3203,22 @@ describe('document', function() { names: { type: [String], default: null + }, + tags: { + type: [{ tag: String }], + default: null } }); const Model = db.model('Test', schema); const m = new Model(); assert.strictEqual(m.names, null); + assert.strictEqual(m.tags, null); await m.save(); const doc = await Model.collection.findOne({ _id: m._id }); assert.strictEqual(doc.names, null); + assert.strictEqual(doc.tags, null); }); it('validation works when setting array index (gh-3816)', async function() {