-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to de-select discriminator key #3230
Comments
Any update or lead on this ? And this is all about memory consumption ; |
@Catatomik can you provide some code samples that show what you're trying to achieve? |
Of course, here's a short code sample : const dbScheduledRoutes = await TBMScheduledRoutesModel.find<DocumentType<ScheduledRoute>>({}, dbScheduledRoutesProjection)
.sort({ _id: 1 })
.populate("trips.schedules", { hor_app: 1, hor_estime: 1, _id: 0 })
.lean()
.exec() My types are made with typegoose. The important part is about @modelOptions({ options: { customName: TBMEndpoints.Schedules } })
export class dbTBM_Schedules extends TimeStamps {
@prop({ required: true })
public hor_theo!: Date;
}
@modelOptions({ options: { customName: TBMEndpoints.Schedules_rt } })
export class dbTBM_Schedules_rt extends dbTBM_Schedules {
@prop({ required: true })
public hor_app!: Date;
@prop({ required: true })
public hor_estime!: Date;
} So when populating through A possible solution would be making an exclusion projection only, and put |
@Catatomik you can also deselect 'use strict';
const mongoose = require('mongoose');
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_test');
const Test = mongoose.model('Test', mongoose.Schema({ name: String }));
const D = Test.discriminator('D', mongoose.Schema({ prop: String }));
await Test.deleteMany({});
await D.create({ name: 'foo', prop: 'bar' });
console.log(await D.findOne().select({ name: 1, prop: 1, _id: 0, __t: 0 })); // { name: 'foo', prop: 'bar' }, no __t
} |
Well I tried that : It might be due to the population ? Or my Schema ? |
What is your discriminator key? Perhaps it is set to a different value than |
I don't think so... {
hor_app: "+275760-09-13T00:00:00.000Z",
hor_estime: "+275760-09-13T00:00:00.000Z",
__t: "TBM_Schedules_rt",
} |
Might be due to populate, we will check |
Looks like it is due to populate(), the following throws 'use strict';
const mongoose = require('mongoose');
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_test');
const Test = mongoose.model(
'Test',
mongoose.Schema({ name: String, arr: [{ testRef: { type: 'ObjectId', ref: 'Test2' } }] })
);
const schema = mongoose.Schema({ name: String });
const Test2 = mongoose.model('Test2', schema);
const D = Test2.discriminator('D', mongoose.Schema({ prop: String }));
await Test.deleteMany({});
await Test2.deleteMany({});
const { _id } = await D.create({ name: 'foo', prop: 'bar' });
let test = await Test.create({ name: 'test', arr: [{ testRef: _id }] });
console.log(await Test.findById(test._id).populate('arr.testRef', { name: 1, prop: 1, _id: 0, __t: 0 }));
} |
As a workaround, use |
fix(populate): allow deselecting discriminator key when populating
Re: #3133.
The text was updated successfully, but these errors were encountered: