Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const options = { discriminatorKey: 'kind' };
- const Event = mongoose.model('Event, new Schema({
- name: { type: String }
- }, options);
- const ClickEvent = Event.discriminator('ClickEvent', new Schema({
- url: { type: String }
- }, options);
- // on another file
- const ClickEvent = mongoose.model('ClickEvent');
- const clickEvent = new ClickEvent({
- name: 'sir',
- url: 'http://somewhere.com/hello'
- });
- console.log(clickEvent); // { name: 'sir', url: 'http://somewhere.com/hello', kind: 'ClickEvent' }
- // look carefully kind is set to ClickEvent
- const ClickEvent = Event.discriminator('ClickEvent', new Schema({
- url: { type: String }
- }, { ...options, discriminatorValue: 'click' });
Add Comment
Please, Sign In to add comment