-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
cannot use where('field', 'LIKE', 123) together with groupBy #2200
Comments
prwnr
changed the title
cannot use
cannot use where('field', 'LIKE', 123) together with groupBy
Feb 12, 2021
where('field', 'LIKE', 123)
together with groupBy
Hello, We have reverted back PR that introduced this regression. Please, update to latest version and let us know if everything is ok. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
Short: Using
where
with aLIKE
on a numeric value in a grouped query causes$where is not allowed in this context
Long: when using where function with a LIKE operator and passing a number as a value together with a groupBy function, mongodb throws exception, because underlying code is using a
$where
within a$match
in an aggregation call to Mongo.so for example
Product::query()->where('code', 'LIKE', 12345)->groupBy('name')->get()
will causeMongoDB\Driver\Exception\CommandException : $where is not allowed in this context
and this is confirmed by documentation:https://docs.mongodb.com/manual/reference/operator/aggregation/match/#restrictions
You cannot use $where in $match queries as part of the aggregation pipeline.
This is caused only when LIKE is being used with numeric value and in conjunction with groupBy (basically with aggregation framework). When Im using LIKE on a string it all works fine (the string needs to be an actual string, not a number in a string type).
Steps to reproduce
Product::query()->where('code', 'LIKE', 12345)->groupBy('name')->get()
Expected behaviour
I would rather expect the above query to work fine together with a group by. Is there a reason that it's working like this?
Additional info
This is the place in code that generates the
$where
which is later used in a$match
https://github.com/jenssegers/laravel-mongodb/blob/master/src/Jenssegers/Mongodb/Query/Builder.php#L1043
Here's how pipeline used in the aggregation call looks like:
The text was updated successfully, but these errors were encountered: