1

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 ?

Neil Lunn
  • 140,271
  • 35
  • 313
  • 302
Shashika
  • 1,536
  • 6
  • 27
  • 45
  • mongo dbname command.js > output.json http://stackoverflow.com/questions/13104800/printing-mongodb-shell-output-to-file – MartenCatcher Nov 20 '13 at 08:32

2 Answers2

1

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>" }
] )
Parvin Gasimzade
  • 23,335
  • 8
  • 54
  • 80
0

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.

Community
  • 1
  • 1
Salvador Dali
  • 199,541
  • 138
  • 677
  • 738