Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/schema/documentArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 6 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down