I want to save the aggregation framework result to a new collection. I know that's impossible with the framework at the moment with the command itself.
Is there a workaround in the shell?
aggregate() method returns a cursor to the documents produced by the final stage of the aggregation pipeline operation, or if you include the explain option, the document that provides details on the processing of the aggregation operation.
What is MongoDB $unwind? The MongoDB $unwind operator is used to deconstruct an array field in a document and create separate output documents for each item in the array.
Mongoose Aggregate Class Mongoose's aggregate() function returns an instance of Mongoose's Aggregate class. Aggregate instances are thenable, so you can use them with await and promise chaining. The Aggregate class also supports a chaining interface for building aggregation pipelines.
Starting with Mongo 2.6.0 you can do this natively without any additional manipulation.
db.<collection>.aggregate( [
{ <operation> },
{ <operation> },
...,
{ $out : "<output-collection>" }
] )
Check the new aggregation operator $out for more detailed example.
P.S. using this way you are not limited to 16Mb size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With