I have a query in mongo python which looks like:
collection.find({"name" : {$in : ["foo_foo", "bar_bar"]}})
And I'd like now to match names like "foo_bar", "foo_foe" etcetera. So I used a regular expresion:
collection.find({ $or : [{"name" : {"$regex" : "foo_.*" }},
{"name" : {"$regex" : "bar_.*" }}] })
But when looking for lots of entries, the second query is thousands of times slower. I don't see how to improve this. Any hint would be much appreciated. What really surprises me is that matching a "foo_foo" string should be slower than matching a string "foo_.*".