-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Using two predicates inside one object ignores one of them #4868
Comments
@jannyHou , please take a look? thx. |
@mschnee any chance you can look into this one? thx |
From the docs And and Or Operator, I think and/or should be used in the query when there are more than one conditions. We will make it more clear in the section Not sure how much effort it needs to have such warinings, thoughts? @raymondfeng @jannyHou |
The bad filter is allowed due to type Start with the where clause's type:
The
To fix it, I think we need to ALLOW ONLY ONE operator in |
In that case, the type could look like this:
Does that look okay? I tried making a branch for it: joeytwiddle/predicate-comp-type-1 (Compare) But it fails to build: I can work around it by writing |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
We are trying to count all records with
createTime
between two dates. We are using a MongoDB datasource.We tried the following filter, but it does not do what it looks like it should do. Only the
gte
is being respected. Thelt
is being ignored, so we end up counting more results that we expected to.Fortunately, if we use an
and
clause then we get the results we wanted.So there is a solution.
The real problem is that the
lt
was being silently ignored, so this went undetected in our codebase for some time.Possible solutions
If that
badDateFilter
is illegal, then we could change the TypeScript types to reject it. But I'm guessing that it's a legitimate filter, it's just not being handled well at runtime.(preferred) Fix whatever is causing the
lt
to be ignored, so thebadDateFilter
will actually work as intended.If it's not possible to fix it, then instead throw a runtime error from the library ("This filter cannot be applied correctly"), so that developers will know they need to use an
and
clause instead of combining multiple conditions in one object.Footnotes
In the examples,
createTime
,fromTime
andtoTime
are all Date objects.This
badDateFilter
is quite familiar for MongoDB / mongoose users, although they use$gte
and$lt
.We are using the following packages:
The text was updated successfully, but these errors were encountered: