Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom pipeline operators with MongoDB Aggregation Framework

Actually, I use map reduce to make some calculations. I can't do that with the aggregation framework because there is no available pipeline operators for my calculations.

Is it possible to write custom pipeline operators?

Thanks in advance

like image 741
hotips Avatar asked Nov 28 '12 18:11

hotips


1 Answers

The answer will depend on your definition of "possible":

1) Out of the box: NO.

As at MongoDB 2.2 there is no end user feature to allow you to add new pipeline operators. The Aggregation Framework and pipeline operators are implemented in C++ for improved performance and concurrency over earlier aggregation options such as MapReduce (which is implemented in JavaScript).

2) If you want to write one in C++: YES (but not trivial).

MongoDB is an open source project, so you do have the option of diving into the C++ code and implementing additional functionality yourself (see: src/mongo/db/pipeline). Note that there are guidelines on Contributing to the MongoDB project and ongoing development is extremely active.

If you want to write custom functions, your best option at the moment is to continue using MapReduce.

Regardless of the above options, if there is a pipeline operator or feature you'd like to see please do suggest it in the MongoDB Jira SERVER project (component: Aggregation Framework). This will allow others to comment, watch, and vote on the feature request .. and if you do end up implementing the feature yourself you can reference the Jira feature description in your pull request. Before submitting a new feature request, you should also search to see if perhaps this feature has already been suggested.

For example, there are already requests such as:

  • SERVER-4929: $group should have a $median accumulator

  • SERVER-5044: $stdDev aggregation operator for standard deviation

  • SERVER-7463: More operators for Aggregation Framework (percentile, top)

like image 85
Stennie Avatar answered Sep 22 '22 12:09

Stennie