Skip to content

Commit

Permalink
Merge pull request #11804 from Automattic/gh-11580
Browse files Browse the repository at this point in the history
on is no longer a reserved word gh-11580
  • Loading branch information
vkarpov15 committed May 16, 2022
2 parents c2bd9a9 + 3d17528 commit 2dc8de8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ reserved['prototype'] =
// EventEmitter
reserved.emit =
reserved.listeners =
reserved.on =
reserved.removeListener =

// document properties and functions
Expand Down
15 changes: 14 additions & 1 deletion test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ describe('schema', function() {
describe('reserved keys are log a warning (gh-9010)', () => {
this.afterEach(() => sinon.restore());
const reservedProperties = [
'emit', 'listeners', 'on', 'removeListener', /* 'collection', */ // TODO: add `collection`
'emit', 'listeners', 'removeListener', /* 'collection', */ // TODO: add `collection`
'errors', 'get', 'init', 'isModified', 'isNew', 'populated',
'remove', 'save', 'toObject', 'validate'
];
Expand Down Expand Up @@ -2764,6 +2764,19 @@ describe('schema', function() {
assert(batch.message);
});

it('can use on as a schema property (gh-11580)', async() => {
const testSchema = new mongoose.Schema({
on: String
});
const Test = db.model('gh11580', testSchema);
await Test.create({
on: 'Test'
});
const result = await Test.findOne();
assert.ok(result);
assert.ok(result.on);
});

it('disallows using schemas with schema-level projections with map subdocuments (gh-11698)', async function() {
const subSchema = new Schema({
selected: { type: Number },
Expand Down

0 comments on commit 2dc8de8

Please sign in to comment.