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

Regex query is not working. #96

Open
prashanthsun9 opened this issue Jul 12, 2017 · 1 comment
Open

Regex query is not working. #96

prashanthsun9 opened this issue Jul 12, 2017 · 1 comment

Comments

@prashanthsun9
Copy link

prashanthsun9 commented Jul 12, 2017

I am not sure what I am doing wrong but this below query is not working, can you help?

        if($this->input->has('filter')){
            $filter =  array( 'name' => array( '$regex' => $this->input->get('filter')) );
        }else{
            $filter = [];
        }
        $rawBrands = Brands::find($filter, ['name' => 1], [], 20, $skip);

I get no results, but if I executed the same query directly in mongodb I get lots of matched records, is $regex working in this lib?
The result that i get is always empty, but it should not be the case, either I should get all the brands or the brands that match the filter and yes I do have lots of documents in brand collection which match the search criteria.

@prashanthsun9
Copy link
Author

Found a solution my self. you could include this in your Documentation, we need to us MongoRegex.

$filter = array( 'name' => array( '$regex' => new MongoRegex("/^".$this->input->get('filter')."/i")) );

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

1 participant