Currently math operations like add, subtract, divide etc. are available for aggregation framework. In some case it would be great to have a possibility to make some simple calculations on update.
For example, we have an collection of event groups. There are timestamps of the first and last occurred events. An end user wants to see long lasting groups. Currently there are 2 options to do that:
1. When a new event comes in we should query Mongo to get existing group, then make calculations and update this document
- Negative moment: we have to query database to fetch previous data
2. Simply update a group entity and later on build aggregation query to fetch long lasting groups (use $project with $subtract and then $match)
- Negative moment: scan of all documents to make calculations
MongoDB has a few simple math operations on update ($inc, $mul, $min, $max) so it would be great to extend the list with few more simple operations.
Moreover, these functions should be able to work with values of document fields, i.e.:
$set : {"duration" : { $subtract : ["$lastTimestamp", "$firstTimestamp"]}} or $set : {"duration" : { $subtract : ["$lastTimestamp", ISODate("2016-03-03T00:00:00.000Z")]}}
- duplicates
-
SERVER-22893 Update should provide more than $inc $min $max etc.
- Closed
- is related to
-
SERVER-11345 Allow update to compute expressions using referenced fields like Aggregation Framework's $project
- Closed