1

I want to use Mongo DB MapReduce functionality along with Aggregation Query.

The below are the stages which I see could be part of the Aggregation pipeline.

  1. Filter docs for which the user has access based on content in the docs and passed security context(roles of the user) (Using $REDACT)
  2. Filter based on one or more criteria (Using MATCH)
  3. Tokenize the words in returned docs based on above filtering and populate a collection (Using MAPREDUCE) (OR) return the docs inline
  4. Query the populated collection/returned docs inline for words based on user criteria using like query(REGEX) and return the words along with their locations

I able to achieve steps 1,2 and 4 in the aggregation pipeline.

I am able to achieve Stage 3, separately by using mapreduce functionality in Mongo DB.

I want to make the mapreduce operation also as a stage in the aggregation pipeline and use it to receive the filtered docs from the earlier steps and pass the processed result to next step.

The mapreduce operation is based on sample map and reduce operation. I intend to use the map , reduce and finalize functions as shared in the below stackoverflow issue.

Implement auto-complete feature using MongoDB search

My query is I do now know if we can have MapReduce operation as part of the Mongo DB aggregation pipeline and if so can we use as inline and pass it to the next stage.

I am using Spring Data Mongo DB to implement the Mongo DB aggregation solution.

If someone has implemented the same please help me on this.

Community
  • 1
  • 1
Jbaur
  • 135
  • 2
  • 10
  • You cannot use the MapReduce framework in combination with the aggregation pipeline as you desire, but the aggregation framework does [support text search via the $text predicate](https://docs.mongodb.com/manual/reference/operator/aggregation/match/#restrictions), so long as it is the first stage. Would that work? – Charlie Swanson Apr 25 '17 at 19:08

0 Answers0