First off, I’d like to say I’m a noob and I have only recently started making “bigger” apps with Meteor. I’m having a problem updating an array value inside a Mongo collection in Meteor. Here is an example document:
{
"_id" : "2rhqEN8yjLf8kReJn",
"name" : "John",
"age" : 34,
"userId" : "AE7iW5ZuByvpMCKd6",
"chapters" : [
{
"id" : "qwmkKJb4Zbk6svGHh",
"name" : "chapter1",
"done" : false
},
{
"id" : "vxnEwtJpxNnK5xaZm",
"name" : "chapter2",
"done" : false
},
{
"id" : "nqX5gbpCSmujNEyJm",
"name" : "chapter3",
"done" : false
}
}
I basically have an event on a checkbox to change (update) that “done” value on click. The problem is, I’ve tried many different methods and none have worked right so far. Here is my current code:
Meteor.methods({
toggleCheckbox: function(id, checkid, done) {
Students.update(
{ _id: id, "chapters.id": checkid},
{ $set: { "chapters.$.done" : done } }
);
}
});
As you can see I’m using a method. In case you need it, here is the event:
Template.student.events({
'change #chapterComplete': function() {
var data = Template.instance().data;
Meteor.call('toggleCheckbox', data._id, this.id, !this.done);
}
});
I have spent way too long on this, and I feel like it’s some small mistake I’m making somewhere. Any help would be greatly appreciated.