Skip to content

Commit

Permalink
Merge pull request #12467 from lpizzinidev/fix-ignore-select
Browse files Browse the repository at this point in the history
fix(query): select: false was ignored for Map
  • Loading branch information
vkarpov15 committed Sep 25, 2022
2 parents 6153970 + e505b1f commit 8a63b6a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/queryhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ exports.applyPaths = function applyPaths(fields, schema) {
schema.eachPath(function(path, type) {
if (prefix) path = prefix + '.' + path;
if (type.$isSchemaMap || path.endsWith('.$*')) {
if (type.options && type.options.select === false) {
excluded.push(path);
}
return;
}
let addedPath = analyzePath(path, type);
Expand Down
24 changes: 24 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4108,4 +4108,28 @@ describe('Query', function() {
});
});
});

it('select: false is ignored for type Map (gh-12445)', async function() {
const testSchema = new mongoose.Schema({
select: {
type: Map,
of: Object
},
doNotSelect: {
type: Map,
of: Object,
select: false
}
});

const Test = db.model('Test', testSchema);
await Test.create({
select: { key: { some: 'value' } },
doNotSelect: { otherKey: { someOther: 'value' } }
});

const item = await Test.findOne();
assert.equal(item.get('select.key.some'), 'value');
assert.equal(item.doNotSelect, undefined);
});
});

0 comments on commit 8a63b6a

Please sign in to comment.