Navigation Menu

Skip to content
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

Closed
vkarpov15 opened this issue Mar 28, 2017 · 5 comments
Closed

Report error if populating on non-existent path #5124

vkarpov15 opened this issue Mar 28, 2017 · 5 comments
Labels
backwards-breaking developer-experience This issue improves error messages, debugging, or reporting discussion If you have any thoughts or comments on this issue, please share them!
Milestone

Comments

@vkarpov15
Copy link
Collaborator

#5036 (comment)

@vkarpov15 vkarpov15 added the discussion If you have any thoughts or comments on this issue, please share them! label Mar 28, 2017
@vkarpov15 vkarpov15 added this to the 5.0 milestone Mar 28, 2017
@TrejGun
Copy link
Contributor

TrejGun commented Mar 28, 2017

in strict mode?

@vkarpov15
Copy link
Collaborator Author

@TrejGun yeah I presume turning off this behavior if strict is off would be prudent

@vkarpov15 vkarpov15 added backwards-breaking developer-experience This issue improves error messages, debugging, or reporting labels Mar 21, 2020
@vkarpov15 vkarpov15 modified the milestones: Parking Lot, 6.0 Mar 21, 2020
vkarpov15 added a commit that referenced this issue Jun 6, 2020
vkarpov15 added a commit that referenced this issue Jun 6, 2020
vkarpov15 added a commit that referenced this issue Jun 6, 2020
vkarpov15 added a commit that referenced this issue Jun 7, 2020
vkarpov15 added a commit that referenced this issue Jun 8, 2020
vkarpov15 added a commit that referenced this issue Jun 16, 2020
…onal populate is nested under a virtual populate like #8432
vkarpov15 added a commit that referenced this issue Jun 16, 2020
vkarpov15 added a commit that referenced this issue Jun 17, 2020
@taxilian
Copy link
Contributor

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:

ApplicantModel.findOne({_id: applicantId, deleted: {$in: [false, null]}})
        .populate({
            path: 'assignedVeDocs',
            populate: {path: 'ulsRecord'},
        });

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?

@vkarpov15
Copy link
Collaborator Author

@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);
}

@efcjunior
Copy link

I think there is bug about it #10976

@Automattic Automattic locked and limited conversation to collaborators Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backwards-breaking developer-experience This issue improves error messages, debugging, or reporting discussion If you have any thoughts or comments on this issue, please share them!
Projects
None yet
Development

No branches or pull requests

4 participants