Skip to content

Commit dadac4e

Browse files
committed
test: add test case for #14115
1 parent 30315ce commit dadac4e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/query.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,4 +4383,33 @@ describe('Query', function() {
43834383
await Error.find().sort('-');
43844384
}, { message: 'Invalid field "" passed to sort()' });
43854385
});
4386+
4387+
it('does not apply sibling path defaults if using nested projection (gh-14115)', async function() {
4388+
const userSchema = new mongoose.Schema({
4389+
name: String,
4390+
account: {
4391+
amount: Number,
4392+
owner: { type: String, default: () => 'OWNER' },
4393+
taxIds: [Number]
4394+
}
4395+
});
4396+
const User = db.model('User', userSchema);
4397+
4398+
const { _id } = await User.create({
4399+
name: 'test',
4400+
account: {
4401+
amount: 25,
4402+
owner: 'test',
4403+
taxIds: [42]
4404+
}
4405+
});
4406+
4407+
const doc = await User
4408+
.findOne({ _id }, { name: 1, account: { amount: 1 } })
4409+
.orFail();
4410+
assert.strictEqual(doc.name, 'test');
4411+
assert.strictEqual(doc.account.amount, 25);
4412+
assert.strictEqual(doc.account.owner, undefined);
4413+
assert.strictEqual(doc.account.taxIds, undefined);
4414+
});
43864415
});

0 commit comments

Comments
 (0)