Suppose you have a collection called bar in a MongoDB, which has the following items :
"items" : [
    {
        "item_name" : "my_item_one",
        "price" : 20
    },
    {
        "item_name" : "my_item_two",
        "price" : 50
    },
    {
        "item_name" : "my_item_three",
        "price" : 30
    }
]
How can i add a new field called discount to each entry in the items array? I tried this without luck :
var dynamicItem = "items.$.discount"
    Bar.update( {user_id : 123456} , {$set : {dynamicItem : 5} })
 
     
     
    