Pregunta

I got an unexpected behaviour while trying to update all the entries on an anonymous collection (client side). Only one entry is updated instead of all. I expected the following code to return true, it does not:

TEST = new Meteor.Collection(null); // create the anonymous collection client side
TEST.insert({"val":true}); // add a minimal entry
TEST.insert({"val":true}); // add a second minimal entry
TEST.update({}, {"val":false}); // I expect to update all the entries to {"val":false}
TEST.find({"val":true}).count() === 0; // the count gives 1, only the first entry was updated (expected 0)

It's either a bug, or something I did not got about updates… could someone clarify ? Note: Obviously the code must be copy pasted into the console of a browser running Meteor. (Tried on 0.8.0.1)

¿Fue útil?

Solución

Ok got it… I just forgot to use the {multi:true} option… shame on me

TEST = new Meteor.Collection(null);
TEST.insert({"val":true});
TEST.insert({"val":true});
TEST.update({}, {"val":false}, {multi:true});
TEST.find({"val":true}).count() === 0; // works
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top