-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
The BSON Regex type is sorted as so:
- Compare the match expression
- If the match expression is equal, compare the options
The options comparisons seems to be the reason why some code, sometimes, alphabetize the valid regex options, so the options "xi" are ordered before "ms", because some tools (such as the shell) rewrite the "xi" options to "ix", and therefore sorting before "ms".
Some code within the server alludes to this to, but does not itself verify, or even guarantee, the order when printing or otherwise exporting such types.
Besides it being a tad weird to rely on alphabetically ordered options for sorting, I think the server itself should be ordering the options is wants the values if it deems their order to be significant, not relying on the clients doing so:
> db.regex.insert({reg: new RegExp("hello", "yimg")}) WriteResult({ "nInserted" : 1 }) > db.regex.insert({reg: /hello/yimg}) WriteResult({ "nInserted" : 1 }) > db.regex.find({reg: {$type: "regex"}}).sort({"reg": 1}) { "_id" : ObjectId("5825221bad899b26f25b1de7"), "reg" : /hello/gimy } { "_id" : ObjectId("5825221fad899b26f25b1de8"), "reg" : /hello/gimy }
- is related to
-
SERVER-26991 Inconsistent handling of RegEx options
- Closed