Re: Express Mathematical functions like sin, cos in aggregation

451 views
Skip to first unread message

Jenna deBoisblanc

unread,
Oct 24, 2012, 2:00:21 PM10/24/12
to mongod...@googlegroups.com
There are currently no operators in the aggregation framework for this these types of calculations.  You can, however, use Javascript Math functions in Map Reduce. Here is a good example using MR to calculate the standard deviation:

If you would like help with your MR command, please let us know.


On Wednesday, October 24, 2012 1:24:50 AM UTC-4, Farmer John wrote:
I was looking at the mongodb aggregation framework reference[link]. The arithmetic operators were all the basic ones $add, $multiply, $divide, $mod et al. Suppose one of my pipes cannot be expressed simply in these operators but requires other mathematical operators like sin, cos, tan, logs. Is there a way to express  such mathematical functions in your pipe. Suppose for example, I have two fields in my collection A and B. They both store numbers (doubles - 64 Bit). I have to express
C = Math.sqrt(-Math.log(A) * sin(B))

Then select the top 5  'C' values. How would I express in aggregation. Can we write functions like those in mapreduce. And give a reference to those functions in our pipeline. Sorry if this is silly. The mongo reference page for aggregation could do with more `concrete` examples.

Thanks

Jenna deBoisblanc

unread,
Oct 31, 2012, 5:27:15 PM10/31/12
to mongodb-user
Yes indeed :)

Please feel free to create, track, and up vote tickets in JIRA, and if
possible, please link the tickets to this thread for other interested
community members.

On Oct 27, 1:02 pm, Farmer John <oldwineinnewbot...@gmail.com> wrote:
> The operation which I intended was supposed to be real time or pseudo real
> time. Map reduce would perhaps take ages to complete.
>
> Instead, if I file a JIRA ticket, will the awesome developers at 10gen
> consider this as a feature request.
>
> On Wednesday, October 24, 2012 11:30:21 PM UTC+5:30, Jenna deBoisblanc
> wrote:
>
>
>
>
>
>
>
>
>
> > There are currently no operators in the aggregation framework for this
> > these types of calculations.  You can, however, use Javascript Math
> > functions in Map Reduce. Here is a good example using MR to calculate the
> > standard deviation:
> >https://gist.github.com/1886960
>
> > If you would like help with your MR command, please let us know.
>
> > On Wednesday, October 24, 2012 1:24:50 AM UTC-4, Farmer John wrote:
>
> >> I was looking at the mongodb aggregation framework reference[link]<http://docs.mongodb.org/manual/reference/aggregation/>.
Reply all
Reply to author
Forward
0 new messages