Comments (4)
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days
from mongoose.
I'm unable to repro, AFAIK Mongoose does give you the correct discriminator model with findOne()
. For example, consider the following script. Can you please modify the following repro script to demonstrate the issue you're seeing?
'use strict';
const mongoose = require('mongoose');
run().catch(error => {
console.error(error);
process.exit(-1);
});
async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_test');
const baseModelSchema = new mongoose.Schema({ baseModelProp: String });
const derivedModelSchema = new mongoose.Schema({ derivedModelProp: String });
const baseModel = mongoose.model('BaseModel', baseModelSchema);
const derivedModel = baseModel.discriminator('DerivedModel', derivedModelSchema);
await baseModel.deleteMany({});
const { _id } = await derivedModel.create({ baseModelProp: 'base model test', derivedModelProp: 'derived model test' });
const doc = await baseModel.findById(_id).orFail();
console.log(doc.derivedModelProp); // Prints "derived model test"
console.log(doc instanceof derivedModel); // Prints "true"
}
from mongoose.
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days
from mongoose.
This issue was closed because it has been inactive for 19 days and has been marked as stale.
from mongoose.
Related Issues (20)
- BSON Timestamp in a mongoose schema HOT 1
- The return type of connection.tranaction method should not be Promise<void>.
- [Feature] Add option to disable filters on each method HOT 2
- InferRawDocType returns `unknown` for every property instead of the right type HOT 2
- TS: _id not required on DocumentArray properties of documents returned from query HOT 3
- Embedded documents are missing the `toJSON()` method HOT 1
- Can not creating a Schema with a field named 'parent' HOT 8
- Query recursive model with discriminator not working with string ref id filter HOT 1
- await mongoose.connect() not fully connected HOT 3
- how to search objectid with regex? HOT 3
- địt con bà chúng mày
- Example for findOneAndUpdate is confusing HOT 2
- Unable to use `$pull` on nested array within discriminated union
- Document.prototype.validate() does not validate subdocument required fields with validateModifiedOnly option HOT 1
- BulkWrite updateOne with filter $elemMatch { $elemMatch: { $in: [] } } throwing TypeError HOT 1
- Model.hydrate() should work with subdocument array projection
- Private PKG: MongooseError: Operation `users.findOne()` buffering timed out after 10000ms HOT 1
- DocumentNotFoundError: No document found for query on using delete function HOT 2
- In which case the ID field is automatically converted to ObjectId? HOT 1
- Query.count / Query.findOneAndRemove are still alive
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.