-
-
Notifications
You must be signed in to change notification settings - Fork 752
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
Error when using recursive populate on mongoose document element with empty array #583
Comments
You will find your issues might be handled faster is they are posted to the repo they affect, feathers-hooks-common in this case. Preliminaries for fix are in feathersjs-ecosystem/feathers-hooks-common#190 |
I think you would want to use include: {
service: 'users',
nameAs: 'users',
parentField: 'users',
childField: '_id',
asArray: true, // workaround
include: [ ... ]
} |
Fixed in feathersjs-ecosystem/feathers-hooks-common#191 which will be published as v3.3.3. Please confirm the fix works for you. Could you afterwards close this issue? Thanks. |
Thank you eddyystop and sorry for the wrong repo. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
Steps to reproduce
Create 3 mongoose documents with references ex. channels,users,groups. Channel can have 0:n users, user can have 0:1 groups. Channels schema has users defined like this:
users: [{type: mongooseClient.Schema.Types.ObjectId, ref: 'users', required: true}]
so when you create new Channel document, without any users, mongoose adds by design
users: []
to new document. Then add populate schema to channel hooks
include: { service: 'users', nameAs: 'users', parentField: 'users', childField: '_id', include: [ { service: 'groups', nameAs: 'group', parentField: 'group', childField: '_id' } ] }
and then fetch channels.
You will get an error:
I also tried non recursive populate with users only and it worked. When i remove those Channels users where they are empty, it works with recursive schema. So only recursive population has problem with empty arrays.
Expected behavior
I would expect that populateItemArray would check if items are an empty array and return again an empty array. Same when i use non recursive populate schema.
Actual behavior
It throws an error.
System configuration
Tell us about the applicable parts of your setup.
The text was updated successfully, but these errors were encountered: