I have produced some results through mongodb aggregation framework. So now I need to get those results to a file(text or any other format).
How can I achieve this ?
I have produced some results through mongodb aggregation framework. So now I need to get those results to a file(text or any other format).
How can I achieve this ?
Check the $out operator in aggregation framework.
$out operator takes the documents returned by the aggregation pipeline and writes them to a specified collection. The $out operator lets the aggregation framework return result sets of any size. The $out operator must be the last stage in the pipeline.
The command has the following syntax, where is collection that will hold the output of the aggregation operation. $out is only permissible at the end of the pipeline:
db.<collection>.aggregate( [
{ <operation> },
{ <operation> },
...,
{ $out : "<output-collection>" }
] )
Check my answer to a previous question how to export output of the aggregation framework to a new collection. After exporting to a new collection you can simply do mongodump.