laravel-mongodb
laravel-mongodb copied to clipboard
Regex Queries are slow
- 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();