I assume (please correct me if I am wrong) that all aggregation pipelines calculations take place in the mongodb server, not in the client.
This question is about best practises and computational efficiency.
Take for instance a document like this:
{
_id: mongoose.Schema.ObjectID,
name: 'James Brown',
job: 'singer',
relationships: [
{ type: 'wife', duration: 2 },
{ type: 'manager', duration: 10 },
{ type: 'friend', duration: 40 }
...
]
}
Where we want to have a new document field which will represent the total duration (in years) of all relationships.
My question is; What is more efficient in a situation like before, running aggregation pipelines every time or calculating client sided once?
By calculating client-sided I mean specifically, fetching the document from database, doing the calculations with Javascript and finally updating the document with the new field.