-
-
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
Report error if populating on non-existent path #5124
Comments
in strict mode? |
@TrejGun yeah I presume turning off this behavior if strict is off would be prudent |
…tion Cleanup to help out with #5124
…or both virtual and conventional populate Re: #5124
…onal populate is nested under a virtual populate like #8432
Before I create a new issue, I want to verify if this is "as designed" -- I get this error if I do a nested populate -- is that expected? e.g:
This is a 100% valid populate, but it throws the "strictPopulate" error, presumably because it doesn't follow through the refs to see that it does actually know about ulsRecord on the ref that assignedVeDocs populates to. Bug or design feature? |
@taxilian I believe this is the issue we discussed in Slack on Friday. Without looking at the schema, I can't tell. I'll paste the script I posted in Slack for posterity that demonstrates this works. const mongoose = require('mongoose');
const { Schema } = mongoose;
run().catch(err => console.log(err));
async function run() {
console.log(mongoose.version);
await mongoose.connect('mongodb://localhost:27017/test');
await mongoose.connection.dropDatabase();
const VELinkSchema = new Schema({ ve: 'ObjectId' });
VELinkSchema.virtual('veDoc', {
ref: 'VE',
localField: 've',
foreignField: '_id',
justOne: true
});
const parentSchema = new Schema({ assignedVes: [VELinkSchema] });
const veSchema = new Schema({ call: String });
veSchema.virtual('ulsRecord', {
ref: 'UlsActiveCallsigns',
localField: 'call',
foreignField: 'callsign',
justOne: true,
});
const ulsSchema = new Schema({ callsign: String });
const Parent = mongoose.model('Test', parentSchema);
const VE = mongoose.model('VE', veSchema);
const ULS = mongoose.model('UlsActiveCallsigns', ulsSchema);
await ULS.create({ callsign: 'Maverick' });
const ve = await VE.create({ call: 'Maverick' });
let p = await Parent.create({ assignedVes: [{ ve: ve._id }] });
p = await Parent.findOne().populate({
path: 'assignedVes.veDoc',
populate: {path: 'ulsRecord'},
}).exec();
console.log(p.assignedVes[0].veDoc.ulsRecord.callsign);
} |
I think there is bug about it #10976 |
#5036 (comment)
The text was updated successfully, but these errors were encountered: