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

Mongoose query with unprojection on dynamic zone field causes error #6016

Closed
atlmtw opened this issue Apr 30, 2020 · 4 comments
Closed

Mongoose query with unprojection on dynamic zone field causes error #6016

atlmtw opened this issue Apr 30, 2020 · 4 comments
Labels
good first issue Good for newcomers issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@atlmtw
Copy link
Contributor

atlmtw commented Apr 30, 2020

Describe the bug
When creating a custom controller on a content type that has a dynamic zone field, excluding it from the selection of the query causes an error (Mongoose). For instance lets say we have dynamic zone field called "modules".

If my query looks like this:

strapi.query("name")
  .model
  .find({},{modules:0}); <-- Excluding it from selection through field projection

Then it causes an error with the strapi-mongoose-connector library. If I don't include "modules" in it, it works. If I try to unproject another field that is not a dynamic zone field, it works.

My custom controller code looks like this:
Screen Shot 2020-04-30 at 5 23 15 PM

The error message I get is in this screen shot:
Screen Shot 2020-04-30 at 5 52 04 PM

It appears that the library is still trying to map on the dynamic zone field despite it not being in the returned query.

Expected behavior
It should return all objects that match the query of the controller without the "modules" dynamic zone field.

System

  • Node.js version: v12.16.2
  • NPM version: 6.14.4
  • Strapi version: 3.0.0-beta.20.1
  • Database: MongoDB 4.2.6
  • Operating system: Ubuntu 18.04 LTS

Thanks again and as always I appreciate the work the Strapi team does!

@atlmtw atlmtw changed the title Mongoose model unprojection on dynamic zone field causes error strapi-mongoose-connector - query with unprojection on dynamic zone field causes error Apr 30, 2020
@atlmtw atlmtw changed the title strapi-mongoose-connector - query with unprojection on dynamic zone field causes error strapi-connector-mongoose - query with unprojection on dynamic zone field causes error Apr 30, 2020
@lauriejim lauriejim changed the title strapi-connector-mongoose - query with unprojection on dynamic zone field causes error Mongoose query with unprojection on dynamic zone field causes error May 7, 2020
@lauriejim lauriejim added good first issue Good for newcomers severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members issue: bug Issue reporting a bug labels May 7, 2020
@lauriejim
Copy link
Contributor

Thank you for reporting this issue, I ping @alexandrebodin about that.

@alexandrebodin
Copy link
Member

Hi @atlmtw There is an automatic population of dynamic zones hence the code running. It is a pretty easy fix to check if there is data before trying to process it. A good first PR if you want ;)

@atlmtw
Copy link
Contributor Author

atlmtw commented May 12, 2020

Hey @alexandrebodin! Maybe ill try it out later tonight and submit a PR.

alexandrebodin pushed a commit that referenced this issue Jul 6, 2020
This is to ensure custom mongoose queries that exclude dynamic zone fields don't fail.

Referring to this issue:
#6016
@alexandrebodin
Copy link
Member

Closing as #6916 was merged. It will be available in the next release :)

gilfernandes pushed a commit to onepointconsulting/strapi that referenced this issue Aug 13, 2020
This is to ensure custom mongoose queries that exclude dynamic zone fields don't fail.

Referring to this issue:
strapi#6016

Signed-off-by: Gil Fernandes <gil.fernandes@onepointltd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
None yet
Development

No branches or pull requests

3 participants