Given the following document, I want to rename "Doc" to "doc". I thought maybe I could use $rename within a forEach but no such luck.
db.getCollection('Docs').find({}).forEach(
function(doc){
doc.history.forEach(function(d2){
var id = d2._id
db.collection.update(d2, {$rename:{"Doc": "doc"}});
print(d2);
})
}
)
{
"_id": "ObjectId(\"5b85c223e959480ea8b2c6d2",
"history"[{
"Doc": {},
"Doc": {},
"Doc": {}
}
]
}