I need to update every record in a collection with a new field.
My documents look something like:
{
words:['apple','banana','porridge']
}
and I want to add a new field called word_count that holds the length of the words array (the array length is static).
{
words:['apple','banana','porridge'],
word_count : 3
}
I've tried things along the lines of:
update({}, {$set: {word_count: words.length}}, {multi: true});
And I could do a forEach, however we are talking a fairly large data set of over 2 million rows, so for each is not the most efficient... unless of course it's the only way.