I have a MongoDB database containing frequencies of words in the document level as shown below. I have about 175k documents in the same format, totaling about 2.5GB.
{
"_id": xxx,
"title": "zzz",
"vectors": {
"word1": 28,
"word2": 22,
"word3": 12,
"word4": 7,
"word5": 4
}
Now I want to iterate through all documents, calculate the sum of all frequencies for each word, and get a total ranking of these words I have in the vectors field based on the frequencies as such:
{
"vectors": {
"word1": 223458,
"word2": 98562,
"word3": 76433,
"word4": 4570,
"word5": 2599
}
$unwind does not seem to work here as I have a nested dictionary. I'm relatively new to MongoDB, and I couldn't find answers specific to this. Any ideas?