diff --git a/packages/mongo-livedata/collection.js b/packages/mongo-livedata/collection.js index 0984811555..9a3fcd8f37 100644 --- a/packages/mongo-livedata/collection.js +++ b/packages/mongo-livedata/collection.js @@ -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 diff --git a/packages/mongo-livedata/mongo_livedata_tests.js b/packages/mongo-livedata/mongo_livedata_tests.js index 62178eccc0..1f0fc98035 100644 --- a/packages/mongo-livedata/mongo_livedata_tests.js +++ b/packages/mongo-livedata/mongo_livedata_tests.js @@ -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'}},