I have a mongodb file with the following structure
> db.user.find().limit(1); { "_id" : "1", "foo" : { "bars" : [ { "name" : "bar1" }, { "name" : "bar2" }, ], ... }, ... }
I want to add a new property to each bar . I have my script iterate over a bars array, but I cannot get a new property there, how can I do this?
var users = db.user.find({"foo.bars":{$exists:true}}); users.forEach(function(user) { user.foo.bars.forEach(function(bar) { printjson(bar);
source share