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
  • 148,042
  • 36
  • 346
  • 317
Shashika
  • 1,606
  • 6
  • 28
  • 47
  • 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
  • 25,180
  • 8
  • 56
  • 83
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
  • 214,103
  • 147
  • 703
  • 753