I have a query that may be too complicated for MongoDB to execute it quickly. If there are things that I can change in how my MongoDB is setup, I'd love to know!
Here is an example query that is search the jobs collection for the term "api"
db.jobs.find(
{
'budget': {'$exists': true, '$ne': ''},
'$or': [
{'title': /(^|[\\s.,])api.*/gi},
{'query': /api'/gi},
{'description': /(^|[\\s.,])api.*/gi}
]
}
)
This ends up taking more than 3 seconds to run across 32000 documents (excerpt from MongoDB Profiler):
"ntoreturn" : 0,
"ntoskip" : 0,
"nscanned" : 0,
"nscannedObjects" : 34266,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 274,
I was thinking of adding an index on either title, query, description, but MongoDB only allows one text index per collection, while I have three string fields (title, query, description) that I am querying.