Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-22940

Add support of more math operations on update

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying, Write Ops
    • None
    • Query
    • Fully Compatible

      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")]}}
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            bondyk Yuriy Bondaruk
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: