mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Replaced an _.each call with a Object.keys().forEach call, to allow objects with length properties to be handled properly as Mongo selectors. (#8380)
This commit is contained in:
@@ -378,7 +378,8 @@ Mongo.Collection._rewriteSelector = function (selector) {
|
||||
return {_id: Random.id()};
|
||||
|
||||
var ret = {};
|
||||
_.each(selector, function (value, key) {
|
||||
Object.keys(selector).forEach((key) => {
|
||||
const value = selector[key];
|
||||
// Mongo supports both {field: /foo/} and {field: {$regex: /foo/}}
|
||||
if (value instanceof RegExp) {
|
||||
ret[key] = convertRegexpToMongoSelector(value);
|
||||
@@ -388,8 +389,7 @@ Mongo.Collection._rewriteSelector = function (selector) {
|
||||
// override the ones set on $regex.
|
||||
if (value.$options !== undefined)
|
||||
ret[key].$options = value.$options;
|
||||
}
|
||||
else if (_.contains(['$or','$and','$nor'], key)) {
|
||||
} else if (_.contains(['$or','$and','$nor'], key)) {
|
||||
// Translate lower levels of $and/$or/$nor
|
||||
ret[key] = _.map(value, function (v) {
|
||||
return Mongo.Collection._rewriteSelector(v);
|
||||
|
||||
@@ -2198,6 +2198,18 @@ Tinytest.add('mongo-livedata - rewrite selector', function (test) {
|
||||
var oid = new Mongo.ObjectID();
|
||||
test.equal(Mongo.Collection._rewriteSelector(oid),
|
||||
{_id: oid});
|
||||
|
||||
// Make sure selectors with "length" properties are handled properly
|
||||
// (verifies issue #8329 has been resolved).
|
||||
const SomeSelector = function (length) {
|
||||
this.length = length;
|
||||
};
|
||||
const length = 2;
|
||||
const testSelector = new SomeSelector(length);
|
||||
test.equal(
|
||||
Mongo.Collection._rewriteSelector(testSelector),
|
||||
{ length }
|
||||
);
|
||||
});
|
||||
|
||||
testAsyncMulti('mongo-livedata - specified _id', [
|
||||
|
||||
Reference in New Issue
Block a user