[SERVER-13902] Reverse regex functionality for queries Created: 11/May/14 Updated: 06/Dec/22 Resolved: 23/Jun/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Fermín Galán Márquez | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Duplicate | Votes: | 22 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Assigned Teams: |
Query
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
The $regex operator allows to search documents having a field which match a given regular expresion passed in the query. However, it would be interesting to have also the opossite: search documents passing a text in the query which is evaluated for matching to a field in the collection storing a regular expresión. I wonder if this feature/improvement is already in MongoDB roadmap as it seems it would be useful for several use cases. See for example:
|
| Comments |
| Comment by Asya Kamsky [ 28/Jan/19 ] | ||||||||
|
As of 3.6 we allow using any aggregation expression in find using $expr so once | ||||||||
| Comment by Sebastian Maier [ 25/Jan/19 ] | ||||||||
|
Thomas described it quite good. Naming wise it could be `$regexApply` or maybe more explicit: `$regexReverse`.
| ||||||||
| Comment by Charlie Swanson [ 23/Jun/17 ] | ||||||||
|
I think the proposal in | ||||||||
| Comment by Michal Idzikowski [ 11/Jun/14 ] | ||||||||
|
Next example that show it's useful: I have telephony system (on SIP protocol) and I look into database for route where call should be dispatched. If someone calls number 77656 it should go via gateway1, if 195959 then through gateway2. I have a lot of regex'es and 12 gateways so the routing table in MySQL have now about 8k records. I cache result for particular number, but it doesn't help, becuase it rarely happens that two people call same number. MongoDB is much faster and such reverse regex functionality will help people like me lowering latency and resources usage. Example data:
Example query:
| ||||||||
| Comment by Fermín Galán Márquez [ 06/Jun/14 ] | ||||||||
|
I'm attaching some slides explaing why reverse regex is useful (use case) | ||||||||
| Comment by Fermín Galán Márquez [ 12/May/14 ] | ||||||||
|
Yes, it does. You have described precisely the functionality I refer to. Thanks! | ||||||||
| Comment by Thomas Rueckstiess [ 12/May/14 ] | ||||||||
|
Hi Fermin, Just to clarify. You mean documents store regular expressions (here in the url field):
And you want to pass in a string as a query and only want the documents whose regular expression matches the string. Perhaps with a special operator (let's call it $regexApply for this example):
Does that describe the feature you are requesting? Thanks |