Skip to content
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

Regexp in whereNot expression #148

Closed
montekidlo opened this issue Feb 27, 2017 · 1 comment
Closed

Regexp in whereNot expression #148

montekidlo opened this issue Feb 27, 2017 · 1 comment

Comments

@montekidlo
Copy link

Hi,

I found strange behavior in whereNot expression, when I did something like this -

use MongoDB\BSON\Regex;

$expression->whereNot((new Expression())->where('foo', new Regex('bar', '')))

I got error -

Can't have regex as arg to $ne

In code:

        foreach ($expression->toArray() as $field => $value) {
             // $not acceptable only for operators-expressions
            if (is_array($value) && is_string(key($value))) {
                $this->where($field, array('$not' => $value));
            } // for single values use $ne
            else {
                $this->whereNotEqual($field, $value);
            }
        }

Maybe it makes sense to add a check for object, something like this?

if (is_array($value) && is_string(key($value)) || is_object($value)) {

@sokil
Copy link
Owner

sokil commented Jun 20, 2017

fixed in 1.21.5

@sokil sokil closed this as completed Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants