Skip to content

Commit bd4440a

Browse files
committed
fix(projection): also handle value objects in isInclusive
1 parent 062016e commit bd4440a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/helpers/projection/isInclusive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const isDefiningProjection = require('./isDefiningProjection');
4+
const isPOJO = require('../isPOJO');
45

56
/*!
67
* ignore
@@ -26,7 +27,7 @@ module.exports = function isInclusive(projection) {
2627
// If field is truthy (1, true, etc.) and not an object, then this
2728
// projection must be inclusive. If object, assume its $meta, $slice, etc.
2829
if (isDefiningProjection(projection[prop]) && !!projection[prop]) {
29-
if (projection[prop] != null && typeof projection[prop] === 'object') {
30+
if (isPOJO(projection[prop])) {
3031
return isInclusive(projection[prop]);
3132
} else {
3233
return !!projection[prop];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
5+
require('../common'); // required for side-effect setup (so that the default driver is set-up)
6+
const isInclusive = require('../../lib/helpers/projection/isInclusive');
7+
8+
describe('isInclusive', function() {
9+
it('handles $elemMatch (gh-14893)', function() {
10+
assert.strictEqual(isInclusive({ field: { $elemMatch: { test: new Date('2024-06-01') } }, otherProp: 1 }), true);
11+
});
12+
});

0 commit comments

Comments
 (0)