-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
@casl/mongoose should use .and
for adding the condition instead of .where
when called on a Query
#272
Comments
.and
for adding the condition instead of .where
.and
for adding the condition instead of .where
when called on a Query
Thanks for the issue! Could you please tell which mongoose version you use? |
I’ll look into this tomorrow morning by Kyiv time. As a workaround I suggest you merge your appointments = await Appointment.find({
startDate: {
$gte: new Date('2020-01-01'),
$lte: new Date('2020-01-05')
},
}).accessibleBy(ability) |
@stalniy I am currently on mongoose 5.9.2 I created a PR that I believe solves the issue if you wanted to take a look at it I am currently combining my conditions, but it would be ideal to have it fixed as it makes it trickier to dynamically generate query conditions, especially if you're adding multiple conditions on the same value. Or of course if you have an actual need for an $and condition |
Sure, I believe I’ll merge in few hours. Just need some time to make sure everything is ok |
…g `$and` conditions Fixes stalniy#272
Released in |
I discovered this issue when I was writing a query that had an
$and
condition, and my query log was showing the condition as$and: [{}]
Given the following example:
The problem is because the
accessibleBy
method uses.where
which will override the$and
parameter, where as the.and
method will add a new condition.The text was updated successfully, but these errors were encountered: