I have got a collection aTable with 2 records:
{
\"title\" : \"record 1\",
\"fields\" : [
{
\"_id\" : 1,
To get what you want you will need a few things:
t.forEach(function( aRow ) {
var newFields = [];
aRow.fields.forEach( function( aField ){
var newItems = [];
aField.items.forEach( function( item ){
var aNewItem = { item: parseInt(item), ref: 0 };
newItems.push( aNewItem );
} );
newFields.push({ _id: aField._id, items: newItems });
} )
aTable.update(
{ _id: aRow._id },
{ "$set": { "fields": newFields } }
);
});
So basically you need to "re-construct" your arrays before updating