Correct mongo selector rewrite for {$regex: /foo/, $options: '...'}

This commit is contained in:
Avital Oliver
2013-07-29 12:41:28 -07:00
parent f7d991cc87
commit a9b59ea867
2 changed files with 10 additions and 2 deletions

View File

@@ -266,6 +266,10 @@ Meteor.Collection._rewriteSelector = function (selector) {
ret[key] = convertRegexpToMongoSelector(value);
} else if (value && value.$regex instanceof RegExp) {
ret[key] = convertRegexpToMongoSelector(value.$regex);
// if value is {$regex: /foo/, $options: ...} then $options
// override the ones set on $regex.
if (value.$options)
ret[key].$options = value.$options;
}
else if (_.contains(['$or','$and','$nor'], key)) {
// Translate lower levels of $and/$or/$nor

View File

@@ -909,7 +909,9 @@ Tinytest.add('mongo-livedata - rewrite selector', function (test) {
{x: /^a/i},
{y: /^b/},
{z: {$regex: /^c/i}},
{w: {$regex: '^[abc]', $options: 'i'}} // make sure we don't break vanilla selectors
{w: {$regex: '^[abc]', $options: 'i'}}, // make sure we don't break vanilla selectors
{v: {$regex: /O/, $options: 'i'}}, // $options should override the ones on the RegExp object
{u: {$regex: /O/m, $options: 'i'}} // $options should override the ones on the RegExp object
]},
{'$nor': [
{s: /^d/},
@@ -923,7 +925,9 @@ Tinytest.add('mongo-livedata - rewrite selector', function (test) {
{x: {$regex: '^a', $options: 'i'}},
{y: {$regex: '^b'}},
{z: {$regex: '^c', $options: 'i'}},
{w: {$regex: '^[abc]', $options: 'i'}}
{w: {$regex: '^[abc]', $options: 'i'}},
{v: {$regex: 'O', $options: 'i'}},
{u: {$regex: 'O', $options: 'i'}}
]},
{'$nor': [
{s: {$regex: '^d'}},