[SERVER-17684] Allow invocation of JavaScript functions/closures from $project Created: 22/Mar/15  Updated: 16/May/15  Resolved: 15/May/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: Alex Paransky Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

There are many functions which are not currently available in $project. For example, quite a few people are asking for string.indexOf("target") functionality, so that the result can be used in $substr command.

Instead of adding each of the functions, simply allow invoking any JavaScript function in the process of creating a $project field. Also, it would be nice to write a closure and invoke it. This way multi-step operations could also be performed.



 Comments   
Comment by Asya Kamsky [ 16/May/15 ]

See SERVER-15926

Comment by Alex Paransky [ 15/May/15 ]

Are there any plans to add additional math functions and string functions, so that we don't have to do things like:

http://stackoverflow.com/questions/17482623/rounding-to-2-decimal-places-using-mongodb-aggregation-framework

{$divide:[
     {$subtract:[ 
          {$multiply:[
             {$divide: ['$ActSls','$PlnSls']},
             10000
          ]}, 
          {$mod:[
             {$multiply:[{$divide: ['$ActSls','$PlnSls']}, 10000 ]},
             1]}
          ]}, 
     100
]}

To try to approximate what the http://www.w3schools.com/jsref/jsref_round.asp normally does?

Comment by Ian Whalen (Inactive) [ 15/May/15 ]

As a design decision we do not want the aggregation pipeline executing javascript.

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