0

On the Linux terminal, I can do a mongodump to stdout using this command:

mongodump --db local --collection allnews --out -

But how do I get this output, and pipe it to a file that then downloads in the browser..?

I have an Apache PHP setup, with the Mongo PHP extension installed.

In PhpMyAdmin for MySQL, for example, you can do an "export", and it pipes the output to a .SQL file.

I want the same feature, but for MongoDB rather than MySQL.

Thanks

The reason I can't do a mongodump to a file is because hard drive space on the server is low.

Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47
kingneil
  • 95
  • 2
  • 7

1 Answers1

0

You could try using passthru combined with proper headers to start download:

<?php
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="dump.txt"');
passthru('mongodump --db local --collection allnews --out -')
malarzm
  • 2,831
  • 2
  • 15
  • 25
  • The problem with this solution, is that "mongodump" actually outputs 2 files... it outputs a .bson file, and it outputs a metadata file... But your solution only saves one single file, "dump.txt".... So, how would I adapt this solution ,so that it outputs 2 files...? THANKS – kingneil Mar 05 '16 at 13:56
  • You could try [`--archive`](https://docs.mongodb.org/manual/reference/program/mongodump/#cmdoption--archive) introduced in 3.2 instead of `--out` – malarzm Mar 05 '16 at 16:44