6

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

Stennie
  • 63,885
  • 14
  • 149
  • 175
hotips
  • 2,575
  • 7
  • 42
  • 59

1 Answers1

9

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:

Stennie
  • 63,885
  • 14
  • 149
  • 175
  • do you know if it's planned to use custom pipeline aggregator with official build ? thanks ! – hotips Nov 28 '12 at 22:21
  • The Aggregation Framework was designed to be extensible (and performant) in C++ .. so user-defined pipeline operators seem an unlikely match. If you vote on feature requests in Jira, these are factored into planning for future releases. Map/Reduce makes a full JavaScript interpreter available for data aggregation/manipulation, with the tradeoff being some efficiency and performance. For comparison of MongoDB aggregation options, see: [group(), $group and MapReduce](http://stackoverflow.com/questions/12337319). – Stennie Nov 28 '12 at 23:41