Creating a new collection from the result of a pipleline

I watched and implemented Lauren Schafer excellent explenation on piplelines & aggregation, but did’nt quiet understand how to take the result and group them in a collection so I can later on create a get request to present them in my table

1 Like

Hello @Asi_Meir.
Mongodb aggregation framework is really interesting and I’m happy to help you understand.

Could you include the video that you watched if possible?

Could you share with me what did you understand about pipeline and aggregation so far? maybe you can make an example to show how you know it. A counting result would be good (do not have to complex just typical with $match, $group, and $project).

A good play to play around with Mongo Aggregation is the Mongo Playground (https://mongoplayground.net/)

Go and play with it :slight_smile:

Hi @Asi_Meir, welcome to the community :wave:.
I guess you are looking for $out stage to dump all the results into a collection.

In brief, $out takes the documents returned by the aggregation pipeline and writes them to a specified collection. Starting in MongoDB 4.4, you can specify the output database.
The $out stage must be the last stage in the pipeline. The $out operator lets the aggregation framework return result sets of any size.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer