Can use of $regex in MongoDB Aggregation Framework be optimized? -
i'm using aggregation framework calculate aggregate values on collection. typical query/operation might include close 1 million documents indexed (the f1/ts match reduces number of documents down 1 million 5 million, set can made smaller depending on query parameters, e.g. timeframe selected).
the $match uses indexed attributes of documents, need include amounts full-text search. option i've used $regex match. unfortunately, can't anchor $regex match start of string since string(s) i'm looking anywhere. text i'm "searching" anywhere few characters in length few thousand.
just running basic comparisons, inclusion of $regex match attribute doubles time calculation takes complete.
- what options optimizing operation?
- is possible achieve other way?
- will text-search available use in aggregation operations in v2.6?
for reference:
operation without $regex
db.my_collection.aggregate( { $match:{ f1:objectid('417abd81...577000006'), ts:{$gte:t1,$lte:t2} } },{ $project:{ ts:1, p:1 } },{ $group:{ _id:"$ts", x: { $sum:"$p" } } });
operation $regex
db.my_collection.aggregate( { $match:{ f1:objectid('417abd81...577000006'), ts:{$gte:t1,$lte:t2} } }, { $match:{ c:{$regex: /somevalue/i} } },{ $project:{ ts:1, p:1 } },{ $group:{ _id:"$ts", x: { $sum:"$p" } } });
Comments
Post a Comment