user1262878
user1262878

Reputation: 67

Cant update meteor collection

I'm new to Meteor, and I can't figure out why this happens? I have a collection called gameCol which I'm trying to update. There is only one single document in the collection which matches the criteria. When I'm updating like this:

gameCol.update({started:true}, {$set:{started:false}});

Meteor throws

Meteor.Error.prototype = new Error; at line 144 livedata_common.js

If I'm updating like this:

var status = gameCol.findOne({started:true});
gameCol.update({_id:status._id}, {$set:{started:false}});

everything works as expected.

This seems a bit odd to me, and I can't really find anything that explains it either.

Upvotes: 1

Views: 2477

Answers (1)

mquandalle
mquandalle

Reputation: 2598

Citation form the documentation:

Untrusted code [= js on the client] can only modify a single document at once, specified by its _id. The modification is allowed only after checking any applicable allow and deny rules.

This is for safety reasons (explainations here). So you need to use your second piece of code that works.

Upvotes: 2

Related Questions