1

I want to use MongoDB such as it is like a database version of a spreadsheet with cells: groups of data involved in sum calculations, or inventory with a running total from a document to the next. (of course, other calculation types can be expected)

It means everytime we get an insert/edit/delete it is needed to run the re-calculation for something that is maybe involved in a further calculation thus, the result might be itself a trigger for another re-calculation.

Is there a built-in way to test insert/edit/delete that would call re-calculation methods? (maybe in cascade if a result has an effect on a next re-calculation)

I suppose, such trigger would call a specific function and would supply it with: Attribute name (inserted/edited/deleted), Collection, Document ID, operation type and maybe previous and new values)

(attribute and document level triggers)

I suppose, another way to see it is have a recurring function constantly reading oplog files and act accordingly.

Thanks, Marc

EMHmark7
  • 87
  • 8

1 Answers1

0

As of the current version (3.0.2), MongoDB has no support for triggers, let alone cascading triggers. Documents with fields which depend on the values of other fields are also something you have to implement on the application layer.

As a database which leaves almost all the application logic to the application, functionality like this isn't really in the scope of its design.

When you really want to use MongoDB for this project (IMO it doesn't seem to be the right tool for this project at all), you will have to implement all of this yourself.

You could either implement this on the application, but this could turn ugly when you have long chains of field dependencies as you need to retrieve and save every document one after another. Or you could try to modify MongoDB itself to add support for this. MongoDB is open source, so you can hack it all you want. When you use the free version, remember to read the license terms of the AGPL which are relevant when you let systems owned by someone else connect to your modified MongoDB.

Philipp
  • 67,764
  • 9
  • 118
  • 153