Find query at child
See original GitHub issueI am trying to use a test case as described in “mongoose-schema-extend”
All is working just as explained there.
But, I would expect it to give me the ability to do a search query on the inherited type. So if we consider the example showed in the link above:
var VehicleSchema = mongoose.Schema({
make : String,
}, { collection : 'vehicles', discriminatorKey : '_type' });
var CarSchema = VehicleSchema.extend({
year : Number
});
var BusSchema = VehicleSchema.extend({
route : Number
})
var Vehicle = mongoose.model('vehicle', VehicleSchema),
Car = mongoose.model('car', CarSchema),
Bus = mongoose.model('bus', BusSchema);
var accord = new Car({
make : 'Honda',
year : 1999
});
var muni = new Bus({
make : 'Neoplan',
route : 33
});
I would expect Car.find({})
to return only the documents which have _type : Car
. Instead, I get all vehicles.
Is there a way to get only the cars except for doing Car.find{"_type":"Car"})
?
Issue Analytics
- State:
- Created 9 years ago
- Comments:9
Top Results From Across the Web
How to Query a Parent-Child Tree in SQL | LearnSQL.com
Example 1: List All Children of 1 Parent ... This is the simplest query, so I'll use it to make you more at...
Read more >Has child query | Elasticsearch Guide [8.5] | Elastic
(Required, query object) Query you wish to run on child documents of the type field. If a child document matches the search, the...
Read more >Searching Nested Child Documents - Apache Solr
Children Query Parser Can be used to retrieve children of a matching document. For a detailed explanation of this parser, see the section...
Read more >parent-child & child-parent soql query custom object
Hi I have university as parent object & college as child object. There is a master-detail relationship defined on child object i.e college...
Read more >.children() | jQuery API Documentation
children () method allows us to search through the children of these elements in the DOM tree and construct a new jQuery object...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Another quick implementation is to use pre hooks to inject the discriminatorKey into conditions:
i add above line. after that facing some problem.
Hi, i have schemas. person staff extend person provider extend person
staff.save() saving data with Discriminator Key __t =‘sfaff’ provider.save() saving data with Discriminator Key __t =‘provider’ person.save() saving data without Discriminator Key
in plugin i did changes
` var patchDiscriminatorKey = function() { this._conditions[key] = this.model.modelName; };
newSchema.pre(‘find’, patchDiscriminatorKey); newSchema.pre(‘findOne’, patchDiscriminatorKey); newSchema.pre(‘count’, patchDiscriminatorKey); newSchema.pre(‘findOneAndRemove’, patchDiscriminatorKey); newSchema.pre(‘findOneAndUpdate’, patchDiscriminatorKey); newSchema.pre(‘update’, patchDiscriminatorKey);
return newSchema; }; ` let me know what is issue.