Closed
Description
- Laravel-mongodb Version: 6.3.1
- PHP Version: 7.4
Description:
When I try to use the LIKE operator with a number, it doesnt work,
Steps to reproduce
- Use $query->where("column", "LIKE", "%29%");
Expected behaviour
Return all rows that contain the value 29 in column
Actual behaviour
Returns nothing
Possible solution
The problem is in the file mongodb/Query/Builder.php specifically in the function called compileWhereBasic.
In this code
if (in_array($operator, ['like', 'not like'])) {
if ($operator === 'not like') {
$operator = 'not';
} else {
$operator = '=';
}
$operator change from like to = and then in this other code, a few lines down
if (!isset($operator) || $operator == '=') {
if ($is_numeric) {
$query = ['$where' => '/^'.$value->getPattern().'/.test(this.'.$column.')'];
} else {
$query = [$column => $value];
}
That check if operator is '=' (what changed a few lanes before) and $is_numeric is true (this is true because our like is with 29) change the query to that and then it doesnt return nothing.
I tried to replace
if ($is_numeric) {
$query = ['$where' => '/^'.$value->getPattern().'/.test(this.'.$column.')'];
} else {
$query = [$column => $value];
}
for
$query = [$column => $value];
and its working.
Logs:
SyntaxError: identifier starts immediately after numeric literal (1/1) CommandException SyntaxError: identifier starts immediately after numeric literalin Count.php line 176