could you please help me to solve following problem:
I have a query which scans a collection to find the result, I would like to create an index (or maybe something else) in order to improve the execution speed.
Here is the SQL equivalent of the query
active=true
AND
exclude_from_search=false
AND
(
full_name_lc like '%buttor%
OR
user_name_lc like '%button%'
OR
first_name_lc like '%button%'
OR last_name_lc like '%button%'
)
AND
group !='Star'
Here is the MongoDB query:
db.user.find({
"active":true,
"exclude_from_search":false,
$or:[
{"full_name_lc":{$regex:"button"}},
{"user_name_lc":{$regex:"button"}},
{"first_name_lc":{$regex:"button"}},
{"last_name_lc":{$regex:"button"}}
],
"group":{$ne:"Star"}
})
Thanks you in advance.
active,exclude_from_searchandgroup. Also put indexes on those. The regexes is not that easy to do as far as I know/button/ias a case insensitive search over the "parent" fields makes much more sense...