I'm using MongoDB, and I have a collection of documents with the following structure:
{
fName:"Foo",
lName:"Barius",
email:"fbarius@example.com",
search:"foo barius"
}
I am building a function that will perform a regular expression search on the search
field. To optimize performance, I have indexed this collection on the search field. However, things are still a bit slow. So I ran an explain()
on a sample query:
db.Collection.find({search:/bar/}).explain();
Looking under the winning plan, I see the following index bounds used:
"search": [
"[\"\", {})",
"[/.*bar.*/, /.*bar.*/]"
]
The second set makes sense - it's looking from anything that contains bar to anything that contains bar. However, the first set baffles me. It appears to be looking in the bounds of ""
inclusive to {}
exclusive. I'm concerned that this extra set of bounds is slowing down my query. Is it necessary to keep? If it's not, how can I prevent it from being included?