laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

Regex Queries are slow

Open ghost opened this issue 3 years ago • 0 comments

  • Laravel-mongodb Version:3.6.*
  • PHP Version: 7.3

Description:

about Regex in your document

use MongoDB\BSON\Regex;

User::where('name', 'regex', new Regex('.*doe', 'i'))->get();

In fact, the query statements executed are strange:

// use
Cusotmer::where('title', 'regex', new Regex("^tom"))->get();
// result
customer.find({"title":{"$regex":{"$regex":"^tom","$options":""}}})

Although it does not affect the results, it will be very slow when the amount of data is large

Correct

When I remove the regex, everything becomes normal

Cusotmer::where('title', new Regex("^tom"))->get();

ghost avatar Mar 16 '22 09:03 ghost