[SERVER-22940] Add support of more math operations on update Created: 03/Mar/16  Updated: 06/Dec/22  Resolved: 29/Dec/17

Status: Closed
Project: Core Server
Component/s: Querying, Write Ops
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Yuriy Bondaruk Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-22893 Update should provide more than $inc ... Closed
Related
is related to SERVER-11345 Allow update to compute expressions u... Closed
Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   

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



 Comments   
Comment by Asya Kamsky [ 29/Dec/17 ]

Closing as duplicate of SERVER-22893

Comment by Ramon Fernandez Marina [ 03/Mar/16 ]

Thanks for your report bondyk, I'm sending it to the Query team for consideration. There's a similar request in SERVER-22893 and both tickets may get folded together at some point, so you may want to watch SERVER-22893 for updates as well.

Regards,
Ramón.

Generated at Thu Feb 08 04:01:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.