-
Notifications
You must be signed in to change notification settings - Fork 140
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
Aggregations with filters on ObjectIds fail in MongooseQueryService #881
Comments
This is probably due to the fact that aggregate expects the following:
@doug-martin Any plans on extending the aggregate query builder to convert fields of type ID to the mongoose ObjectId? |
@h4rm thank you for the bug report and tracking down what's causing it, that helps a lot! There will need to be some investigation on how to identify the fields that should be turned into an objectId. @smolinari do you know a way of doing this? |
So I dug a little bit deeper and overwrite the Two things actually fix the problem: Number 1Replace all string Ids to by the same ObjectIds. I am doing it manually right now but I think it should be possible to gather that information from the schema somehow and do it automatically in the buildAggreateQuery which uses the default buildFilterQuery internally. Maybe I could get help on that. Number 2Call convertToAggregateRepsonse as followed to prevent the above mentioned error when the mongoose aggregate returns an empty array:
This will result in the counts to return as null. Of course, the nicest thing would be to return 0 for all aggregates but at least the request doesn't crash in that case. |
@doug-martin - I'm not so deep into the inner workings of Mongoose. The person who might know better is @JohnMcInall. Scott |
@h4rm this has been fixed in |
That's fantastic. Thanks for your amazing effort guys.
…On Wed, Apr 7, 2021, 7:54 AM Doug Martin ***@***.***> wrote:
@h4rm <https://github.com/h4rm> this has been fixed in v0.25.1!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#881 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELBTXHSMUA3GRQ2HTPGRTTHPXRDANCNFSM4XWYFG3Q>
.
|
Yes. Thanks so much for covering this Doug. Scott |
@doug-martin Is it possible that the same problem persists on the subscription part of the filters? I was secretly hoping it's using the same code underneath :-) |
Version: 0.22
When a DTO has a reference which is specified as follows:
and a schema
currently I cannot filter for the userId in an aggregation:
when I call
countDocuments(filter: {userId:{eq: "123456"} })
because I get the following error:Basically the mongoose aggregate function doesn't return a valid result here. Also, in some cases where the was no result to an aggregate query, I also got this error and not the number 0 as expected.
Filtering for other properties works and I can also filter for a specific userId in a normal query.
I think this is a bug with some unhandled case, but maybe I am misusing something.
The text was updated successfully, but these errors were encountered: