Having issues while adding new values in existing database field's value

there is a form - https://www.taxonomyaustralia.org.au/add-a-paper . Authorised contributors can access this form and add a record – basically the metadata for an article. The form submits a record to the Discoveries_papers collection.

This is the point when the javascript needs to be triggered.

The records in Discoveries_papers each have a field taxonomicGroup and another numberOfNewSpecies. There may be 0->n records for each taxonomicGroup, which is a controlled vocabulary.

The table Taxonomic_Groups has one record for each taxonomic group. This needs to receive the sum of all values in numberOfNewSpecies over all records in Discoveries_papers that match the taxonomic group.

The All record in Taxonomic_Groups then needs to receive the sum of sums.
One way to do this would be to increment the relevant record in Taxonomic_Groups by the number of new species.

It seems to me though that it would be best to recalculate the values each time (otherwise we would also need to deal with the decrement case if a paper is ever deleted, which happens occasionally). I assume the overhead would not be too high.

There may be up to several thousand records in Discoveries_papers.

The endpoint of all this is the page https://www.taxonomyaustralia.org.au/new-species-2019 , which uses repeaters to display the results from Taxonomic_groups.