I'm not sure how to go about this, I need to export a mongodb collection as an .csv. Calling mongoexport with spawn.child_process in node will accomplish this but my mongodb server and node server are currently on separate machines.
How can I remotely call mongoexport on my mongo server from my node server and then get the .csv to the node server?
You will have to open the MongoDB port and connect form the node server. Then use
mongoexport --username user --password pass --host host --db database --collection coll --csv
If it's in a public network make you use authentication.
http://www.mongodb.org/display/DOCS/Security+and+Authentication
Otherwise might be simpler to run an ssh command, run mongoexport on the MongoDb server and then sftp back the file (maybe zip it first).
More info on mongoexport
The answer given by GianPaJ is the solution I'm using, however a shortcoming is that it is only outputting the exported data to the remote host, not to your client.
One work around is to use SCP or SFTP on the exported file. I will update this post if I figure out how to actually transfer that file with a mongoexport option.