Update in forEach on mongodb shell
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( { … Read more