I have a meteor collection "list" that has the following data structure.
"list" : [
{
"_id" : "id",
"author" : "authorId",
"createdOn" : "DateTime",
"description" : "description",
"items" : [
{
"item1" : {
"itemComplete" : "Boolean",
"itemName" : "item name",
"itemDescription" : "item description",
}
},
{
"item2" : {
"itemComplete" : "Boolean",
"itemName" : "item name",
"itemDescription" : "item description",
}
}
],
Users will be able to add arbitrary number of list items. I am trying to figure out how to add itemX programmatically. E.g. I have the following code (which does not work) that gives an idea of what I am trying to accomplish.
var currentItemCount = Lists.find({_id:_currentListId, items:{}}).count() + 1;
var newItemNum = "item" + currentItemCount;
var newListItem = $("#list-item").val();
Lists.update({_id:_currentListId},{$push : {items:{newItemNum:{itemName:newListItem}}}});
I would appreciate any suggestions or hints to help me fix my code. Please let me know if I am missing some information.
Thanks in advance.
Kamal
Give something like this a try: