[SERVER-19256] Support ordinary arithmetic parsing in Aggregation Created: 02/Jul/15  Updated: 06/Dec/22  Resolved: 11/Dec/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Chris Biow Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 1
Labels: usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Participants:

 Description   

Arithmetic expressions in Aggregation must now be coded by hand in a rather quirky JSON prefix notation of the form {$opName: ["$field1", "$field2"]}. This becomes unwieldy and impractical with expressions of even moderate complexity, as the operands themselves become JSON subdocuments.

The server could better perform this function by accepting an expression in conventional infix operator precedence notation as used by most programming languages, of the form {$arithmetic: "field1 opSymbol field2"}. For example,

{$arithmetic: "a * b + c / (d - e)"}

would translate to

{$add:[
  {$multiply: ["$a", "$b"]},
  {$divide: [
    "$c", 
    {$subtract: ["$d", "$e"]
  ]}
]}



 Comments   
Comment by Chris Biow [ 02/Jul/15 ]

A similar request appeared in the comments of SERVER-17684 but was answered exclusively in a narrower context of JavaScript roundoff functions.

Comment by Chris Biow [ 02/Jul/15 ]

Spring Framework SpEL expressions provide a similar capability to encode aggregation arithmetic in ordinary notation.

Generated at Thu Feb 08 03:50:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.