mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Throw error in Mongo.Collection when selector is array, fixes #4804
This commit is contained in:
@@ -328,6 +328,12 @@ Mongo.Collection._rewriteSelector = function (selector) {
|
||||
if (LocalCollection._selectorIsId(selector))
|
||||
selector = {_id: selector};
|
||||
|
||||
if (_.isArray(selector)) {
|
||||
// This is consistent with the Mongo console itself; if we don't do this
|
||||
// check passing an empty array ends up selecting all items
|
||||
throw new Error("Mongo selector can't be an array.");
|
||||
}
|
||||
|
||||
if (!selector || (('_id' in selector) && !selector._id))
|
||||
// can't match anything
|
||||
return {_id: Random.id()};
|
||||
|
||||
@@ -3120,3 +3120,28 @@ Meteor.isServer && Tinytest.add("mongo-livedata - npm modules", function (test)
|
||||
test.isTrue(rawDb);
|
||||
test.isTrue(rawDb.admin);
|
||||
});
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Tinytest.add("mongo-livedata - update/remove don't accept an array as a selector #4804", function (test) {
|
||||
var collection = new Mongo.Collection(Random.id());
|
||||
|
||||
_.times(10, function () {
|
||||
collection.insert({ data: "Hello" });
|
||||
});
|
||||
|
||||
test.equal(collection.find().count(), 10);
|
||||
|
||||
// Test several array-related selectors
|
||||
_.each([[], [1, 2, 3], [{}]], function (selector) {
|
||||
test.throws(function () {
|
||||
collection.remove(selector);
|
||||
});
|
||||
|
||||
test.throws(function () {
|
||||
collection.update(selector, {$set: 5});
|
||||
});
|
||||
});
|
||||
|
||||
test.equal(collection.find().count(), 10);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user