Comments (1)
const mongoose = require('mongoose');
const eventSchema = new mongoose.Schema({
name: String
});
const clickedEventSchema = new mongoose.Schema({ element: String }, { discriminatorKey: 'kind' });
eventSchema.discriminator('ClickedEvent', clickedEventSchema, { value: 'click' });
// ^ this will not be used
const Event = mongoose.model('Event', eventSchema);
const ClickedModel = mongoose.model('Clicked', clickedEventSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const doc = await Event.create({ kind: 'clicked', element: '#hero' });
doc.element; // '#hero'
console.log(doc instanceof ClickedModel); // this should be `true`, this will currently be `false`
console.log('done');
}
run();
from mongoose.
Related Issues (20)
- Add a nullable field, its not same as "required" HOT 1
- Turn off "don't cast update pipelines by default" in favor of a more secure approach HOT 2
- Add TypeScript interface for the new PipelineStage - Vector Search HOT 1
- Add `pre` and `post` function types on Query class
- Nested populate with nested paths and subdocuments is not working fine HOT 6
- Best method to set Query and Lean defaults HOT 4
- Issue with 2dsphere indexes in nested schemas vs subdocuments HOT 2
- (Typescript) toObject on populated documents loses the structure
- Recompiling schema does not reapply discriminators HOT 1
- Using default value on sub documents does not work as expected HOT 3
- Recursion check in toObject breaks mongoose-intl plugin HOT 2
- Model.createSearchIndex() create SIGTERM on DuplicateIndex
- Populate doesn't work - nested path + wildcard + 2 references on a same model
- How to catch MongoNetworkError: connect ECONNREFUSED in Node when using mongoose.createConnection() HOT 2
- Pre and Post (middleware) hooks issue
- getters array in virtualtype for "id" virtual is not deduped HOT 1
- FilterQuery Typing fails for generic type HOT 5
- Change tracking is getting lost on transaction retry HOT 1
- Types break in semver patch change HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose.