-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Nested populate with nested paths and subdocuments is not working fine #14435
Comments
@Saul9201 I've tried debugging this, and what I have found is that the reason the error is coming is because the schema of the path |
Found the reason from the docs. So apparently, any field which is an object but does not have the |
I think yours is a valid use case and it could be implemented by mongoose, but for now you can fix this by converting the Personally, I feel the dotted-string approach for valid paths, even if they are inside nested docs, should work correctly. |
Thank you very much @FaizBShah, I've also been debugging and reached the same conclusion. A possible workaround is to use a Subdocument instead of Nested Path, as this way the path to the const UserSchema = new mongoose.Schema({
extras: [
new mongoose.Schema({
config: new mongoose.Schema({
paymentConfiguration: new mongoose.Schema({
paymentMethods: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Code'
}
]
}),
})
})
],
}); But I agree with you, the schema with Nested Path is also a valid schema and should work correctly. |
Yupp, btw just to clarify, this is only happening because your |
fix(schema): avoid returning string 'nested' as schematype
Prerequisites
Mongoose version
8.2.1
Node.js version
18.19.1
MongoDB server version
7.0.6
Typescript version (if applicable)
No response
Description
When I try to populate a document with nested paths it is not working correctly. I am getting the error: schema.applyGetters is not a function.
Steps to Reproduce
Output:
Expected Behavior
It should return the user document with the array
extras.config.paymentConfiguration.paymentMethods
populated correctlyThe text was updated successfully, but these errors were encountered: