Skip to content

Commit

Permalink
test: repro #9361
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Aug 27, 2020
1 parent 54ed471 commit 8c8751f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/schema.select.test.js
Expand Up @@ -324,6 +324,27 @@ describe('schema select option', function() {
});
});

it('should not project in discriminator key if projected in implicitly with .$ (gh-9361)', function() {
const eventSchema = new Schema({ message: String },
{ discriminatorKey: 'kind', _id: false });

const batchSchema = new Schema({ events: [eventSchema] });
batchSchema.path('events').discriminator('Clicked', new Schema({
element: String
}, { _id: false }));
batchSchema.path('events').discriminator('Purchased', new Schema({
product: String
}, { _id: false }));

const MyModel = db.model('Test', batchSchema);

const query = MyModel.find({ 'events.message': 'foo' }).select({ 'events.$': 1 });
query._applyPaths();

assert.equal(Object.keys(query._fields).length, 1);
assert.ok(query._fields['events.$']);
});

describe('forcing inclusion of a deselected schema path', function() {
it('works', function(done) {
const excluded = new Schema({
Expand Down

0 comments on commit 8c8751f

Please sign in to comment.