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

Populate with spaces get evaluated Cannot populate path `` because it is not in your schema. Set the strictPopulate option to false to override. #13951

Closed
vkarpov15 opened this issue Oct 8, 2023 Discussed in #13939 · 1 comment · Fixed by #13984
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Discussed in #13939

Originally posted by masterbater October 5, 2023
Cannot populate path `` because it is not in your schema. Set the strictPopulate option to false to override.
If you put two spaces between populate I got the error above

 const readings = await Gwapo.find(conditions)
    .populate(
      "user  testgwapo",
      "fname lname isActive height abbrev "
    )

"mongoose": "^6.12.0",

@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Oct 8, 2023
@vkarpov15 vkarpov15 added this to the 7.6.2 milestone Oct 8, 2023
@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Oct 10, 2023
@IslandRhythms
Copy link
Collaborator

IslandRhythms commented Oct 10, 2023

Happens on latest as well. Just need to add new in front of the ObjectId creation.

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
  user: mongoose.Schema.Types.ObjectId,
  address: mongoose.Schema.Types.ObjectId
});

const Test = mongoose.model('Test', testSchema);

async function run() {
  await mongoose.connect('mongodb://localhost:27017');
  await mongoose.connection.dropDatabase();
  await Test.create({
    user: mongoose.Types.ObjectId(),
    address: mongoose.Types.ObjectId()
  })

  await Test.find().populate("user  address");
  console.log('done');
}

run();

@vkarpov15 vkarpov15 modified the milestones: 7.6.4, 7.6.3 Oct 13, 2023
vkarpov15 added a commit that referenced this issue Oct 16, 2023
vkarpov15 added a commit that referenced this issue Oct 17, 2023
fix(populate): handle multiple spaces when specifying paths to populate using space-delimited paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
2 participants