Adding new fields is easy:
db.collection.update(
{ defaulted: { $exists: false }},
{ $set: { defaulted: 0 }},
{ multi: true }
)
Modifying existing fields is a bit harder:
db.collection.find().forEach(function(document) {
var name = document.name.split(' ')
// You need a strategie for names with more then 2 words
db.collection.update(
{ _id: document._id },
{
$set: {
firstname: name[0],
lastname: name[1]
},
$unset: { name: '' }
}
)
})